12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/src/pages/home/home.scss:
--------------------------------------------------------------------------------
1 | page-home {
2 |
3 | }
4 |
--------------------------------------------------------------------------------
/src/pages/home/home.ts:
--------------------------------------------------------------------------------
1 | import { Component } from '@angular/core';
2 | import { NavController } from 'ionic-angular';
3 |
4 | @Component({
5 | selector: 'page-home',
6 | templateUrl: 'home.html'
7 | })
8 | export class HomePage {
9 |
10 | constructor(public navCtrl: NavController) {
11 | }
12 |
13 | // for iOS only and set kOSSettingsKeyAutoPrompt to false in init call
14 | registerForPushNotifications() {
15 | window["plugins"].OneSignal.promptForPushNotificationsWithUserResponse(function(accepted) {
16 | console.log("User accepted notifications: " + accepted);
17 | });
18 | }
19 |
20 | // add tags to users
21 | sendTags() {
22 | window["plugins"].OneSignal.sendTags({key: "value", another_key: "another value"});
23 | console.log("tags sent");
24 | }
25 |
26 |
27 | // get tags and upate one
28 | getAndUpdateTag() {
29 | window["plugins"].OneSignal.getTags(function(tags) {
30 | console.log('Tags Received: ' + JSON.stringify(tags));
31 | window["plugins"].OneSignal.sendTag("another_key", "another key's value changed");
32 | });
33 | }
34 |
35 | // get the OneSignal userId aka playerId
36 | getOneSignalPlayerId() {
37 | window["plugins"].OneSignal.getPermissionSubscriptionState(function(status) {
38 | status.permissionStatus.hasPrompted;
39 | status.permissionStatus.status;
40 |
41 | status.subscriptionStatus.subscribed;
42 | status.subscriptionStatus.userSubscriptionSetting;
43 | status.subscriptionStatus.pushToken;
44 |
45 | //var playerID = status.subscriptionStatus.userId;
46 | console.log(status.subscriptionStatus.userId);
47 | });
48 | }
49 |
50 |
51 | // prompt user to accept sending location data
52 | promptLocation() {
53 | window["plugins"].OneSignal.promptLocation();
54 | console.log('location prompted');
55 | }
56 |
57 |
58 | // send a notification with an image
59 | sendNotificationwithImage() {
60 | window["plugins"].OneSignal.getIds(function(ids) {
61 | var notificationObj = { contents: {en: "message with image"},
62 | include_player_ids: [ids.userId],
63 | big_picture: "https://cdn.pixabay.com/photo/2017/09/16/16/09/sea-2755908_960_720.jpg",
64 |
65 | ios_attachments: {id1: "https://cdn.pixabay.com/photo/2017/09/16/16/09/sea-2755908_960_720.jpg"}
66 | };
67 |
68 | window["plugins"].OneSignal.postNotification(notificationObj,
69 | function(successResponse) {
70 | console.log("Notification Post Success:", successResponse);
71 | },
72 | function (failedResponse) {
73 | console.log("Notification Post Failed: ", failedResponse);
74 | alert("Notification Post Failed:\n" + JSON.stringify(failedResponse));
75 | }
76 | );
77 | });
78 | }
79 |
80 |
81 | // send Notification Action Buttons and Deep Link
82 | sendNotificationWithActionButtonsAndDeepLink() {
83 | window["plugins"].OneSignal.getIds(function(ids) {
84 | var notificationObj = { contents: {en: "Message with Action Buttons and Deep link"},
85 | include_player_ids: [ids.userId],
86 | data: {data_key: "data_value", openURL: "https://imgur.com/"},
87 |
88 | buttons: [{"id": "id1", "text": "Deep Link with URL", "icon": "ic_menu_share"}, {"id": "id2", "text": "just button2", "icon": "ic_menu_send"}]
89 | };
90 |
91 | window["plugins"].OneSignal.postNotification(notificationObj,
92 | function(successResponse) {
93 | console.log("Notification Post Success:", successResponse);
94 | },
95 | function (failedResponse) {
96 | console.log("Notification Post Failed: ", failedResponse);
97 | alert("Notification Post Failed:\n" + JSON.stringify(failedResponse));
98 | }
99 | );
100 | });
101 | }
102 |
103 |
104 |
105 | }
106 |
--------------------------------------------------------------------------------
/src/pages/otherpage/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/OneSignalDevelopers/OneSignal-Ionic-Sample/e5bf7b34b073abea53b7ec8529d47f20d4304cd9/src/pages/otherpage/.DS_Store
--------------------------------------------------------------------------------
/src/pages/otherpage/otherpage.html:
--------------------------------------------------------------------------------
1 |