@@ -102,6 +102,13 @@ public class OSNotificationOpenedResult {
102
102
public OSNotification notification ;
103
103
}
104
104
105
+ public class OSInAppMessageAction {
106
+ public string clickName ;
107
+ public string clickUrl ;
108
+ public bool firstClick ;
109
+ public bool closesMessage ;
110
+ }
111
+
105
112
public enum OSNotificationPermission {
106
113
NotDetermined ,
107
114
Denied ,
@@ -161,6 +168,8 @@ public class OneSignal : MonoBehaviour {
161
168
// result = The Notification open result describing : 1. The notification opened 2. The action taken by the user
162
169
public delegate void NotificationOpened ( OSNotificationOpenedResult result ) ;
163
170
171
+ public delegate void InAppMessageClicked ( OSInAppMessageAction action ) ;
172
+
164
173
public delegate void IdsAvailableCallback ( string playerID , string pushToken ) ;
165
174
public delegate void TagsReceived ( Dictionary < string , object > tags ) ;
166
175
public delegate void PromptForPushNotificationsUserResponse ( bool accepted ) ;
@@ -264,11 +273,12 @@ public enum OSInFocusDisplayOption {
264
273
}
265
274
266
275
public class UnityBuilder {
267
- public string appID = null ;
268
- public string googleProjectNumber = null ;
269
- public Dictionary < string , bool > iOSSettings = null ;
270
- public NotificationReceived notificationReceivedDelegate = null ;
271
- public NotificationOpened notificationOpenedDelegate = null ;
276
+ public string appID ;
277
+ public string googleProjectNumber ;
278
+ public Dictionary < string , bool > iOSSettings ;
279
+ public NotificationReceived notificationReceivedDelegate ;
280
+ public NotificationOpened notificationOpenedDelegate ;
281
+ public InAppMessageClicked inAppMessageClickHandlerDelegate ;
272
282
273
283
// inNotificationReceivedDelegate = Calls this delegate when a notification is received.
274
284
public UnityBuilder HandleNotificationReceived ( NotificationReceived inNotificationReceivedDelegate ) {
@@ -278,7 +288,13 @@ public UnityBuilder HandleNotificationReceived(NotificationReceived inNotificati
278
288
279
289
// inNotificationOpenedDelegate = Calls this delegate when a push notification is opened.
280
290
public UnityBuilder HandleNotificationOpened ( NotificationOpened inNotificationOpenedDelegate ) {
281
- notificationOpenedDelegate = inNotificationOpenedDelegate ; ;
291
+ notificationOpenedDelegate = inNotificationOpenedDelegate ;
292
+ return this ;
293
+ }
294
+
295
+ // inInAppMessageClickHandlerDelegate = Calls this delegate when an In-App Message is opened.
296
+ public UnityBuilder HandlerInAppMessageClicked ( InAppMessageClicked inInAppMessageClickedDelegate ) {
297
+ inAppMessageClickHandlerDelegate = inInAppMessageClickedDelegate ;
282
298
return this ;
283
299
}
284
300
@@ -654,6 +670,44 @@ public static void RemoveExternalUserId()
654
670
#endif
655
671
}
656
672
673
+ public static void AddTrigger ( string key , object value ) {
674
+ #if ONESIGNAL_PLATFORM
675
+ oneSignalPlatform . AddTrigger ( key , value ) ;
676
+ #endif
677
+ }
678
+
679
+ public static void AddTriggers ( Dictionary < string , object > triggers ) {
680
+ #if ONESIGNAL_PLATFORM
681
+ oneSignalPlatform . AddTriggers ( triggers ) ;
682
+ #endif
683
+ }
684
+
685
+ public static void RemoveTriggerForKey ( string key ) {
686
+ #if ONESIGNAL_PLATFORM
687
+ oneSignalPlatform . RemoveTriggerForKey ( key ) ;
688
+ #endif
689
+ }
690
+
691
+ public static void RemoveTriggersForKeys ( IList < string > keys ) {
692
+ #if ONESIGNAL_PLATFORM
693
+ oneSignalPlatform . RemoveTriggersForKeys ( keys ) ;
694
+ #endif
695
+ }
696
+
697
+ public static object GetTriggerValueForKey ( string key ) {
698
+ #if ONESIGNAL_PLATFORM
699
+ return oneSignalPlatform . GetTriggerValueForKey ( key ) ;
700
+ #else
701
+ return null ;
702
+ #endif
703
+ }
704
+
705
+ public static void PauseInAppMessages ( bool pause ) {
706
+ #if ONESIGNAL_PLATFORM
707
+ oneSignalPlatform . PauseInAppMessages ( pause ) ;
708
+ #endif
709
+ }
710
+
657
711
/*** protected and private methods ****/
658
712
#if ONESIGNAL_PLATFORM
659
713
@@ -831,5 +885,25 @@ private void onPromptForPushNotificationsWithUserResponse(string accepted) {
831
885
notificationUserResponseDelegate ( Convert . ToBoolean ( accepted ) ) ;
832
886
}
833
887
888
+ // Called from native SDK
889
+ private void onInAppMessageClicked ( string jsonString ) {
890
+ if ( builder . inAppMessageClickHandlerDelegate == null )
891
+ return ;
892
+
893
+ var jsonObject = Json . Deserialize ( jsonString ) as Dictionary < string , object > ;
894
+
895
+ var action = new OSInAppMessageAction ( ) ;
896
+ if ( jsonObject . ContainsKey ( "click_name" ) )
897
+ action . clickName = jsonObject [ "click_name" ] as String ;
898
+ if ( jsonObject . ContainsKey ( "click_url" ) )
899
+ action . clickUrl = jsonObject [ "click_url" ] as String ;
900
+ if ( jsonObject . ContainsKey ( "closes_message" ) )
901
+ action . closesMessage = ( bool ) jsonObject [ "closes_message" ] ;
902
+ if ( jsonObject . ContainsKey ( "first_click" ) )
903
+ action . firstClick = ( bool ) jsonObject [ "first_click" ] ;
904
+
905
+ builder . inAppMessageClickHandlerDelegate ( action ) ;
906
+ }
907
+
834
908
#endif
835
909
}
0 commit comments