@@ -44,6 +44,8 @@ class _MyAppState extends State<MyApp> with OneSignalPushSubscriptionObserver {
44
44
// Outcome Examples
45
45
oneSignalOutcomeExamples ();
46
46
47
+ OneSignal .shared.login ("Testtesttest" );
48
+
47
49
// OneSignal.shared.setRequiresUserPrivacyConsent(_requireConsent);
48
50
49
51
OneSignal .Notifications
@@ -67,48 +69,29 @@ class _MyAppState extends State<MyApp> with OneSignalPushSubscriptionObserver {
67
69
});
68
70
});
69
71
70
- // OneSignal.shared
71
- // .setInAppMessageClickedHandler((OSInAppMessageAction action) {
72
- // this.setState(() {
73
- // _debugLabelString =
74
- // "In App Message Clicked: \n${action.jsonRepresentation().replaceAll("\\n", "\n")}";
75
- // });
76
- // });
77
-
78
- // OneSignal.shared
79
- // .setSubscriptionObserver((OSSubscriptionStateChanges changes) {
80
- // print("SUBSCRIPTION STATE CHANGED: ${changes.jsonRepresentation()}");
81
- // });
82
-
83
- // OneSignal.shared.setPermissionObserver((OSPermissionStateChanges changes) {
84
- // print("PERMISSION STATE CHANGED: ${changes.jsonRepresentation()}");
85
- // });
86
-
87
- // OneSignal.shared.setEmailSubscriptionObserver(
88
- // (OSEmailSubscriptionStateChanges changes) {
89
- // print("EMAIL SUBSCRIPTION STATE CHANGED ${changes.jsonRepresentation()}");
90
- // });
91
-
92
- // OneSignal.shared.setSMSSubscriptionObserver(
93
- // (OSSMSSubscriptionStateChanges changes) {
94
- // print("SMS SUBSCRIPTION STATE CHANGED ${changes.jsonRepresentation()}");
95
- // });
72
+ OneSignal .InAppMessages
73
+ .setInAppMessageClickedHandler ((OSInAppMessageAction action) {
74
+ this .setState (() {
75
+ _debugLabelString =
76
+ "In App Message Clicked: \n ${action .jsonRepresentation ().replaceAll ("\\ n" , "\n " )}" ;
77
+ });
78
+ });
96
79
97
- // OneSignal.shared .setOnWillDisplayInAppMessageHandler((message) {
98
- // print("ON WILL DISPLAY IN APP MESSAGE ${message.messageId}");
99
- // });
80
+ OneSignal .InAppMessages .setOnWillDisplayInAppMessageHandler ((message) {
81
+ print ("ON WILL DISPLAY IN APP MESSAGE ${message .messageId }" );
82
+ });
100
83
101
- // OneSignal.shared .setOnDidDisplayInAppMessageHandler((message) {
102
- // print("ON DID DISPLAY IN APP MESSAGE ${message.messageId}");
103
- // });
84
+ OneSignal .InAppMessages .setOnDidDisplayInAppMessageHandler ((message) {
85
+ print ("ON DID DISPLAY IN APP MESSAGE ${message .messageId }" );
86
+ });
104
87
105
- // OneSignal.shared .setOnWillDismissInAppMessageHandler((message) {
106
- // print("ON WILL DISMISS IN APP MESSAGE ${message.messageId}");
107
- // });
88
+ OneSignal .InAppMessages .setOnWillDismissInAppMessageHandler ((message) {
89
+ print ("ON WILL DISMISS IN APP MESSAGE ${message .messageId }" );
90
+ });
108
91
109
- // OneSignal.shared .setOnDidDismissInAppMessageHandler((message) {
110
- // print("ON DID DISMISS IN APP MESSAGE ${message.messageId}");
111
- // });
92
+ OneSignal .InAppMessages .setOnDidDismissInAppMessageHandler ((message) {
93
+ print ("ON DID DISMISS IN APP MESSAGE ${message .messageId }" );
94
+ });
112
95
113
96
// iOS-only method to open launch URLs in Safari when set to false
114
97
// OneSignal.shared.setLaunchURLsInApp(false);
@@ -135,19 +118,6 @@ class _MyAppState extends State<MyApp> with OneSignalPushSubscriptionObserver {
135
118
print (stateChanges.jsonRepresentation ());
136
119
}
137
120
138
- void _handleGetTags () {
139
- // OneSignal.shared.getTags().then((tags) {
140
- // if (tags == null) return;
141
-
142
- // setState((() {
143
- // _debugLabelString = "$tags";
144
- // }));
145
- // }).catchError((error) {
146
- // setState(() {
147
- // _debugLabelString = "$error";
148
- // });
149
- // });
150
- }
151
121
152
122
void _handleSendTags () {
153
123
print ("Sending tags" );
@@ -158,11 +128,17 @@ class _MyAppState extends State<MyApp> with OneSignalPushSubscriptionObserver {
158
128
OneSignal .User .addTags (sendTags);
159
129
}
160
130
131
+ void _handleRemoveTag () {
132
+ print ("Deleting tag" );
133
+ OneSignal .User .removeTag ("test2" );
134
+
135
+ print ("Deleting tags array" );
136
+ OneSignal .User .removeTags (['test' ]);
137
+ }
138
+
161
139
void _handlePromptForPushPermission () {
162
140
print ("Prompting for Permission" );
163
- // OneSignal.shared.promptUserForPushNotificationPermission().then((accepted) {
164
- // print("Accepted permission: $accepted");
165
- // });
141
+ OneSignal .Notifications .requestPermission (true );
166
142
}
167
143
168
144
void _handleGetDeviceState () async {
@@ -225,13 +201,7 @@ class _MyAppState extends State<MyApp> with OneSignalPushSubscriptionObserver {
225
201
OneSignal .Location .setShared (true );
226
202
}
227
203
228
- void _handleRemoveTag () {
229
- print ("Deleting tag" );
230
- OneSignal .User .removeTag ("test2" );
231
-
232
- print ("Deleting tags array" );
233
- OneSignal .User .removeTags (['test' ]);
234
- }
204
+
235
205
236
206
void _handleSetExternalUserId () {
237
207
print ("Setting external user ID" );
@@ -304,33 +274,35 @@ class _MyAppState extends State<MyApp> with OneSignalPushSubscriptionObserver {
304
274
}
305
275
306
276
oneSignalInAppMessagingTriggerExamples () async {
307
- // /// Example addTrigger call for IAM
308
- // /// This will add 1 trigger so if there are any IAM satisfying it, it
309
- // /// will be shown to the user
310
- // OneSignal.shared.addTrigger("trigger_1", "one");
311
-
312
- // /// Example addTriggers call for IAM
313
- // /// This will add 2 triggers so if there are any IAM satisfying these, they
314
- // /// will be shown to the user
315
- // Map<String, Object> triggers = new Map<String, Object>();
316
- // triggers["trigger_2"] = "two";
317
- // triggers["trigger_3"] = "three";
318
- // OneSignal.shared.addTriggers(triggers);
319
-
320
- // // Removes a trigger by its key so if any future IAM are pulled with
321
- // // these triggers they will not be shown until the trigger is added back
322
- // OneSignal.shared.removeTriggerForKey("trigger_2");
323
-
324
- // // Get the value for a trigger by its key
325
- // Object? triggerValue = await OneSignal.shared.getTriggerValueForKey("trigger_3");
326
- // print("'trigger_3' key trigger value: ${triggerValue?.toString()}");
327
-
328
- // // Create a list and bulk remove triggers based on keys supplied
329
- // List<String> keys = ["trigger_1", "trigger_3"];
330
- // OneSignal.shared.removeTriggersForKeys(keys);
331
-
332
- // // Toggle pausing (displaying or not) of IAMs
333
- // OneSignal.shared.pauseInAppMessages(false);
277
+ /// Example addTrigger call for IAM
278
+ /// This will add 1 trigger so if there are any IAM satisfying it, it
279
+ /// will be shown to the user
280
+ OneSignal .InAppMessages .addTrigger ("trigger_1" , "one" );
281
+
282
+ /// Example addTriggers call for IAM
283
+ /// This will add 2 triggers so if there are any IAM satisfying these, they
284
+ /// will be shown to the user
285
+ Map <String , Object > triggers = new Map <String , Object >();
286
+ triggers["trigger_2" ] = "two" ;
287
+ triggers["trigger_3" ] = "three" ;
288
+ OneSignal .InAppMessages .addTriggers (triggers);
289
+
290
+ // Removes a trigger by its key so if any future IAM are pulled with
291
+ // these triggers they will not be shown until the trigger is added back
292
+ OneSignal .InAppMessages .removeTrigger ("trigger_2" );
293
+
294
+
295
+ // Create a list and bulk remove triggers based on keys supplied
296
+ List <String > keys = ["trigger_1" , "trigger_3" ];
297
+ OneSignal .InAppMessages .removeTriggers (keys);
298
+
299
+ OneSignal .InAppMessages .clearTriggers ();
300
+
301
+ // Toggle pausing (displaying or not) of IAMs
302
+ OneSignal .InAppMessages .paused (false );
303
+ var arePaused = await OneSignal .InAppMessages .arePaused ();
304
+ print ('Notifications paused ${arePaused }' );
305
+
334
306
}
335
307
336
308
oneSignalOutcomeExamples () async {
@@ -370,10 +342,10 @@ class _MyAppState extends State<MyApp> with OneSignalPushSubscriptionObserver {
370
342
new OneSignalButton (
371
343
"Send Tags" , _handleSendTags, ! _enableConsentButton)
372
344
]),
373
- // new TableRow(children: [
374
- // new OneSignalButton("Prompt for Push Permission",
375
- // _handlePromptForPushPermission, !_enableConsentButton)
376
- // ]),
345
+ new TableRow (children: [
346
+ new OneSignalButton ("Prompt for Push Permission" ,
347
+ _handlePromptForPushPermission, ! _enableConsentButton)
348
+ ]),
377
349
// new TableRow(children: [
378
350
// new OneSignalButton(
379
351
// "Print Device State",
0 commit comments