2727
2828#if ONE_SIGNAL_INSTALLED
2929using System ;
30- using OneSignalSDK ;
3130using UnityEngine ;
3231using 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 ;
3832using 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 ;
3939
4040// ReSharper disable InconsistentNaming
4141// ReSharper disable CheckNamespace
@@ -65,9 +65,14 @@ public class OneSignalExampleBehaviour : MonoBehaviour {
6565
6666 /// <summary>
6767 /// 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
6969 /// </summary>
70- public bool requiresUserPrivacyConsent ;
70+ public bool consentRequired ;
71+
72+ /// <summary>
73+ ///
74+ /// </summary>
75+ public bool consentGiven ;
7176
7277 /// <summary>
7378 /// used to set if launch URLs should be opened in safari or within the application
@@ -119,6 +124,16 @@ public class OneSignalExampleBehaviour : MonoBehaviour {
119124 /// </summary>
120125 public float outcomeValue ;
121126
127+ /// <summary>
128+ ///
129+ /// </summary>
130+ public string liveActivityId ;
131+
132+ /// <summary>
133+ ///
134+ /// </summary>
135+ public string liveActivityToken ;
136+
122137 /// <summary>
123138 /// we recommend initializing OneSignal early in your application's lifecycle such as in the Start method of a
124139 /// MonoBehaviour in your opening Scene
@@ -131,13 +146,13 @@ private void Start() {
131146 _log ( $ "Initializing with appId <b>{ appId } </b>") ;
132147 OneSignal . Default . Initialize ( appId ) ;
133148
134- // Setting RequiresPrivacyConsent to true will prevent the OneSignalSDK from operating until
149+ // Setting ConsentRequired to true will prevent the OneSignalSDK from operating until
135150 // PrivacyConsent is also set to true
136- OneSignal . Default . RequiresPrivacyConsent = requiresUserPrivacyConsent ;
151+ OneSignal . Default . ConsentRequired = consentRequired ;
137152
138153 // Setup the below to listen for and respond to events from notifications
139154 OneSignal . Default . Notifications . Clicked += _notificationOnClick ;
140- OneSignal . Default . Notifications . WillShow += _notificationOnDisplay ;
155+ OneSignal . Default . Notifications . ForegroundWillDisplay += _notificationOnDisplay ;
141156 OneSignal . Default . Notifications . PermissionChanged += _notificationPermissionChanged ;
142157
143158 // Setup the below to listen for and respond to events from in-app messages
@@ -155,63 +170,66 @@ private void Start() {
155170 * SDK events
156171 */
157172
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 ) } ") ;
160176 }
161177
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 )
165181 : null ;
166182
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 ( ) ;
169186 }
170187
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 } ") ;
173190 }
174191
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 ) } ") ;
177194 }
178195
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 ) } ") ;
181198 }
182199
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 ) } ") ;
185202 }
186203
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 ) } ") ;
189206 }
190207
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 ( ) ) ;
193212 }
194213
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 ) } ") ;
197217 }
198218
199219 /*
200220 * SDK setup
201221 */
202222
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 ;
210227 }
211228
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 ;
215233 }
216234
217235 public void SetLogLevel ( ) {
@@ -314,6 +332,12 @@ public void ClearPush() {
314332 _log ( "Notifications cleared" ) ;
315333 }
316334
335+ public void GetPermissionNative ( ) {
336+ var permissionNative = OneSignal . Default . Notifications . PermissionNative ;
337+
338+ _log ( $ "Permission Native is: <b>{ permissionNative . ToString ( ) } </b>") ;
339+ }
340+
317341 /*
318342 * In-App Messages
319343 */
@@ -402,6 +426,28 @@ public void ToggleLaunchURLsInApp() {
402426 OneSignal . Default . SetLaunchURLsInApp ( launchURLsInApp ) ;
403427 }
404428
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+
405451#region Rendering
406452 /*
407453 * You can safely ignore everything in this region and below
@@ -429,6 +475,9 @@ public void ToggleLaunchURLsInApp() {
429475 public void SetOutcomeKey ( string newVal ) => outcomeKey = newVal ;
430476 public void SetOutcomeValue ( string newVal ) => outcomeValue = Convert . ToSingle ( newVal ) ;
431477
478+ public void SetLiveActivityId ( string newVal ) => liveActivityId = newVal ;
479+ public void SetLiveActivityToken ( string newVal ) => liveActivityToken = newVal ;
480+
432481 private void Awake ( ) {
433482 SDKDebug . LogIntercept += _log ;
434483 SDKDebug . WarnIntercept += _warn ;
0 commit comments