27
27
28
28
#if ONE_SIGNAL_INSTALLED
29
29
using System ;
30
- using OneSignalSDK ;
31
30
using UnityEngine ;
32
31
using UnityEngine . UI ;
33
- using OneSignalSDK . Debug . Utilities ;
34
- using OneSignalSDK . Debug . Models ;
35
- using OneSignalSDK . Notifications . Models ;
36
- using OneSignalSDK . InAppMessages . Models ;
37
- using OneSignalSDK . User . Models ;
38
32
using System . Collections . Generic ;
33
+ using OneSignalSDK ;
34
+ using OneSignalSDK . Notifications ;
35
+ using OneSignalSDK . InAppMessages ;
36
+ using OneSignalSDK . User . Models ;
37
+ using OneSignalSDK . Debug . Models ;
38
+ using OneSignalSDK . Debug . Utilities ;
39
39
40
40
// ReSharper disable InconsistentNaming
41
41
// ReSharper disable CheckNamespace
@@ -65,9 +65,14 @@ public class OneSignalExampleBehaviour : MonoBehaviour {
65
65
66
66
/// <summary>
67
67
/// whether you would prefer OneSignal Unity SDK prevent initialization until consent is granted via
68
- /// <see cref="OneSignal.RequiresPrivacyConsent "/> in this test MonoBehaviour
68
+ /// <see cref="OneSignal.ConsentRequired "/> in this test MonoBehaviour
69
69
/// </summary>
70
- public bool requiresUserPrivacyConsent ;
70
+ public bool consentRequired ;
71
+
72
+ /// <summary>
73
+ ///
74
+ /// </summary>
75
+ public bool consentGiven ;
71
76
72
77
/// <summary>
73
78
/// used to set if launch URLs should be opened in safari or within the application
@@ -119,6 +124,16 @@ public class OneSignalExampleBehaviour : MonoBehaviour {
119
124
/// </summary>
120
125
public float outcomeValue ;
121
126
127
+ /// <summary>
128
+ ///
129
+ /// </summary>
130
+ public string liveActivityId ;
131
+
132
+ /// <summary>
133
+ ///
134
+ /// </summary>
135
+ public string liveActivityToken ;
136
+
122
137
/// <summary>
123
138
/// we recommend initializing OneSignal early in your application's lifecycle such as in the Start method of a
124
139
/// MonoBehaviour in your opening Scene
@@ -131,13 +146,13 @@ private void Start() {
131
146
_log ( $ "Initializing with appId <b>{ appId } </b>") ;
132
147
OneSignal . Default . Initialize ( appId ) ;
133
148
134
- // Setting RequiresPrivacyConsent to true will prevent the OneSignalSDK from operating until
149
+ // Setting ConsentRequired to true will prevent the OneSignalSDK from operating until
135
150
// PrivacyConsent is also set to true
136
- OneSignal . Default . RequiresPrivacyConsent = requiresUserPrivacyConsent ;
151
+ OneSignal . Default . ConsentRequired = consentRequired ;
137
152
138
153
// Setup the below to listen for and respond to events from notifications
139
154
OneSignal . Default . Notifications . Clicked += _notificationOnClick ;
140
- OneSignal . Default . Notifications . WillShow += _notificationOnDisplay ;
155
+ OneSignal . Default . Notifications . ForegroundWillDisplay += _notificationOnDisplay ;
141
156
OneSignal . Default . Notifications . PermissionChanged += _notificationPermissionChanged ;
142
157
143
158
// Setup the below to listen for and respond to events from in-app messages
@@ -155,63 +170,66 @@ private void Start() {
155
170
* SDK events
156
171
*/
157
172
158
- private void _notificationOnClick ( INotificationClickedResult result ) {
159
- _log ( $ "Notification was clicked with Action: { JsonUtility . ToJson ( result . Action ) } ") ;
173
+ private void _notificationOnClick ( object sender , NotificationClickEventArgs e ) {
174
+ _log ( $ "Notification was clicked with Notification: { JsonUtility . ToJson ( e . Notification ) } ") ;
175
+ _log ( $ "Notification was clicked with Result: { JsonUtility . ToJson ( e . Result ) } ") ;
160
176
}
161
177
162
- private INotification _notificationOnDisplay ( INotification notification ) {
163
- var additionalData = notification . AdditionalData != null
164
- ? Json . Serialize ( notification . AdditionalData )
178
+ private void _notificationOnDisplay ( object sender , NotificationWillDisplayEventArgs e ) {
179
+ var additionalData = e . Notification . AdditionalData != null
180
+ ? Json . Serialize ( e . Notification . AdditionalData )
165
181
: null ;
166
182
167
- _log ( $ "Notification was received in foreground: { JsonUtility . ToJson ( notification ) } \n { additionalData } ") ;
168
- return notification ; // show the notification
183
+ _log ( $ "Notification was received in foreground: { JsonUtility . ToJson ( e . Notification ) } \n { additionalData } ") ;
184
+
185
+ e . Notification . Display ( ) ;
169
186
}
170
187
171
- private void _iamWillDisplay ( IInAppMessage inAppMessage ) {
172
- _log ( $ "IAM will display : { JsonUtility . ToJson ( inAppMessage ) } ") ;
188
+ private void _notificationPermissionChanged ( object sender , NotificationPermissionChangedEventArgs e ) {
189
+ _log ( $ "Notification Permission changed to : { e . Permission } ") ;
173
190
}
174
191
175
- private void _iamDidDisplay ( IInAppMessage inAppMessage ) {
176
- _log ( $ "IAM did display: { JsonUtility . ToJson ( inAppMessage ) } ") ;
192
+ private void _iamWillDisplay ( object sender , InAppMessageWillDisplayEventArgs e ) {
193
+ _log ( $ "IAM will display: { JsonUtility . ToJson ( e . Message ) } ") ;
177
194
}
178
195
179
- private void _iamWillDismiss ( IInAppMessage inAppMessage ) {
180
- _log ( $ "IAM will dismiss : { JsonUtility . ToJson ( inAppMessage ) } ") ;
196
+ private void _iamDidDisplay ( object sender , InAppMessageDidDisplayEventArgs e ) {
197
+ _log ( $ "IAM did display : { JsonUtility . ToJson ( e . Message ) } ") ;
181
198
}
182
199
183
- private void _iamDidDismiss ( IInAppMessage inAppMessage ) {
184
- _log ( $ "IAM did dismiss: { JsonUtility . ToJson ( inAppMessage ) } ") ;
200
+ private void _iamWillDismiss ( object sender , InAppMessageWillDismissEventArgs e ) {
201
+ _log ( $ "IAM will dismiss: { JsonUtility . ToJson ( e . Message ) } ") ;
185
202
}
186
203
187
- private void _iamOnClick ( InAppMessageClickedResult result ) {
188
- _log ( $ "IAM was clicked with Action : { JsonUtility . ToJson ( result . Action ) } ") ;
204
+ private void _iamDidDismiss ( object sender , InAppMessageDidDismissEventArgs e ) {
205
+ _log ( $ "IAM did dismiss : { JsonUtility . ToJson ( e . Message ) } ") ;
189
206
}
190
207
191
- private void _notificationPermissionChanged ( bool permission ) {
192
- _log ( $ "Notification Permission changed to: { permission } ") ;
208
+ private void _iamOnClick ( object sender , InAppMessageClickEventArgs e ) {
209
+ _log ( $ "IAM was clicked with Message: { JsonUtility . ToJson ( e . Message ) } ") ;
210
+ _log ( $ "IAM was clicked with Result: { JsonUtility . ToJson ( e . Result ) } ") ;
211
+ _log ( $ "IAM was clicked with Result UrlTarget: " + e . Result . UrlTarget . ToString ( ) ) ;
193
212
}
194
213
195
- private void _pushSubscriptionChanged ( IPushSubscriptionState current ) {
196
- _log ( $ "Push subscription changed: { JsonUtility . ToJson ( current ) } ") ;
214
+ private void _pushSubscriptionChanged ( object sender , PushSubscriptionChangedEventArgs e ) {
215
+ _log ( $ "Push subscription changed from previous: { JsonUtility . ToJson ( e . State . Previous ) } ") ;
216
+ _log ( $ "Push subscription changed to current: { JsonUtility . ToJson ( e . State . Current ) } ") ;
197
217
}
198
218
199
219
/*
200
220
* SDK setup
201
221
*/
202
222
203
- public void ToggleRequiresPrivacyConsent ( ) {
204
- if ( OneSignal . Default . RequiresPrivacyConsent )
205
- _error ( $ "Cannot toggle RequiresPrivacyConsent from TRUE to FALSE") ;
206
- else {
207
- _log ( $ "Toggling RequiresPrivacyConsent to <b>{ ! OneSignal . Default . RequiresPrivacyConsent } </b>") ;
208
- OneSignal . Default . RequiresPrivacyConsent = ! OneSignal . Default . RequiresPrivacyConsent ;
209
- }
223
+ public void ToggleConsentRequired ( ) {
224
+ consentRequired = ! consentRequired ;
225
+ _log ( $ "Toggling ConsentRequired to <b>{ consentRequired } </b>") ;
226
+ OneSignal . Default . ConsentRequired = consentRequired ;
210
227
}
211
228
212
- public void TogglePrivacyConsent ( ) {
213
- _log ( $ "Toggling PrivacyConsent to <b>{ ! OneSignal . Default . PrivacyConsent } </b>") ;
214
- OneSignal . Default . PrivacyConsent = ! OneSignal . Default . PrivacyConsent ;
229
+ public void ToggleConsentGiven ( ) {
230
+ consentGiven = ! consentGiven ;
231
+ _log ( $ "Toggling PrivacyConsent to <b>{ consentGiven } </b>") ;
232
+ OneSignal . Default . ConsentGiven = consentGiven ;
215
233
}
216
234
217
235
public void SetLogLevel ( ) {
@@ -314,6 +332,12 @@ public void ClearPush() {
314
332
_log ( "Notifications cleared" ) ;
315
333
}
316
334
335
+ public void GetPermissionNative ( ) {
336
+ var permissionNative = OneSignal . Default . Notifications . PermissionNative ;
337
+
338
+ _log ( $ "Permission Native is: <b>{ permissionNative . ToString ( ) } </b>") ;
339
+ }
340
+
317
341
/*
318
342
* In-App Messages
319
343
*/
@@ -402,6 +426,28 @@ public void ToggleLaunchURLsInApp() {
402
426
OneSignal . Default . SetLaunchURLsInApp ( launchURLsInApp ) ;
403
427
}
404
428
429
+ public async void EnterLiveActivityAsync ( ) {
430
+ _log ( $ "Entering Live Activity with id: <b>{ liveActivityId } </b> and token: <b>{ liveActivityToken } </b> and awaiting result...") ;
431
+
432
+ var result = await OneSignal . Default . LiveActivities . EnterAsync ( liveActivityId , liveActivityToken ) ;
433
+
434
+ if ( result )
435
+ _log ( "Live Activity enter success" ) ;
436
+ else
437
+ _log ( "Live Activity enter failed" ) ;
438
+ }
439
+
440
+ public async void ExitLiveActivityAsync ( ) {
441
+ _log ( $ "Exiting Live Activity with id: <b>{ liveActivityId } </b> and awaiting result...") ;
442
+
443
+ var result = await OneSignal . Default . LiveActivities . ExitAsync ( liveActivityId ) ;
444
+
445
+ if ( result )
446
+ _log ( "Live Activity exit success" ) ;
447
+ else
448
+ _log ( "Live Activity exit failed" ) ;
449
+ }
450
+
405
451
#region Rendering
406
452
/*
407
453
* You can safely ignore everything in this region and below
@@ -429,6 +475,9 @@ public void ToggleLaunchURLsInApp() {
429
475
public void SetOutcomeKey ( string newVal ) => outcomeKey = newVal ;
430
476
public void SetOutcomeValue ( string newVal ) => outcomeValue = Convert . ToSingle ( newVal ) ;
431
477
478
+ public void SetLiveActivityId ( string newVal ) => liveActivityId = newVal ;
479
+ public void SetLiveActivityToken ( string newVal ) => liveActivityToken = newVal ;
480
+
432
481
private void Awake ( ) {
433
482
SDKDebug . LogIntercept += _log ;
434
483
SDKDebug . WarnIntercept += _warn ;
0 commit comments