com.onesignal.unity.ios 5.0.0-beta.2 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/Editor/BuildPostProcessor.cs +1 -1
  2. package/Editor/OneSignaliOSDependencies.xml +1 -1
  3. package/Editor/PBXProjectExtensions.cs +1 -1
  4. package/LICENSE.md +1 -1
  5. package/Runtime/AssemblyInfo.cs +1 -1
  6. package/Runtime/OneSignaliOS.cs +26 -44
  7. package/Runtime/OneSignaliOSInit.cs +2 -2
  8. package/Runtime/Plugins/iOS/OneSignalBridgeUtil.h +4 -3
  9. package/Runtime/Plugins/iOS/OneSignalBridgeUtil.mm +20 -10
  10. package/Runtime/Plugins/iOS/OneSignalUnityBridge.mm +5 -32
  11. package/Runtime/Plugins/iOS/OneSignalUnityBridgeDebug.mm +1 -1
  12. package/Runtime/Plugins/iOS/OneSignalUnityBridgeInAppMessages.mm +26 -29
  13. package/Runtime/Plugins/iOS/OneSignalUnityBridgeLiveActivities.mm +58 -0
  14. package/Runtime/Plugins/iOS/OneSignalUnityBridgeLiveActivities.mm.meta +37 -0
  15. package/Runtime/Plugins/iOS/OneSignalUnityBridgeLocation.mm +1 -1
  16. package/Runtime/Plugins/iOS/OneSignalUnityBridgeNotifications.mm +62 -23
  17. package/Runtime/Plugins/iOS/OneSignalUnityBridgeSession.mm +1 -1
  18. package/Runtime/Plugins/iOS/OneSignalUnityBridgeUser.mm +8 -24
  19. package/Runtime/Plugins/iOS/UIApplication+OneSignalUnity.h +1 -1
  20. package/Runtime/Plugins/iOS/UIApplication+OneSignalUnity.mm +1 -1
  21. package/Runtime/Utilities/WaitingProxy.cs +1 -1
  22. package/Runtime/iOSDebugManager.cs +1 -1
  23. package/Runtime/iOSDisplayableNotification.cs +41 -0
  24. package/Runtime/iOSDisplayableNotification.cs.meta +11 -0
  25. package/Runtime/iOSInAppMessagesManager.cs +84 -27
  26. package/Runtime/iOSLiveActivitiesManager.cs +56 -0
  27. package/Runtime/iOSLiveActivitiesManager.cs.meta +11 -0
  28. package/Runtime/iOSLocationManager.cs +2 -2
  29. package/Runtime/iOSNotificationsManager.cs +77 -52
  30. package/Runtime/iOSPushSubscription.cs +15 -4
  31. package/Runtime/iOSSessionManager.cs +1 -1
  32. package/Runtime/iOSUserManager.cs +1 -1
  33. package/package.json +2 -2
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * Modified MIT License
3
3
  *
4
- * Copyright 2022 OneSignal
4
+ * Copyright 2023 OneSignal
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  * of this software and associated documentation files (the "Software"), to deal
@@ -31,9 +31,9 @@
31
31
  #import "OneSignalBridgeUtil.h"
32
32
 
33
33
  typedef void (*BooleanResponseDelegate)(int hashCode, bool response);
34
- typedef void (*StringListenerDelegate)(const char* response);
35
- typedef void (*StateListenerDelegate)(const char* current);
36
- typedef bool (*NotificationWillShowDelegate)(const char* notification);
34
+ typedef void (*PermissionListenerDelegate)(bool permission);
35
+ typedef void (*WillDisplayListenerDelegate)(const char* notification);
36
+ typedef void (*ClickListenerDelegate)(const char* notification, const char* resultActionId, const char* resultUrl);
37
37
 
38
38
  /*
39
39
  * Helpers
@@ -45,10 +45,13 @@ typedef bool (*NotificationWillShowDelegate)(const char* notification);
45
45
  * Observer singleton for global callbacks
46
46
  */
47
47
 
48
- @interface OneSignalNotificationsObserver : NSObject <OSPermissionObserver>
48
+ @interface OneSignalNotificationsObserver : NSObject <OSNotificationPermissionObserver, OSNotificationLifecycleListener, OSNotificationClickListener>
49
49
 
50
50
  + (instancetype) sharedNotificationsObserver;
51
- @property StateListenerDelegate permissionDelegate;
51
+ @property PermissionListenerDelegate permissionDelegate;
52
+ @property WillDisplayListenerDelegate willDisplayDelegate;
53
+ @property ClickListenerDelegate clickDelegate;
54
+ @property NSMutableDictionary<NSString *, id> *willDisplayEvents;
52
55
 
53
56
  @end
54
57
 
@@ -66,15 +69,44 @@ typedef bool (*NotificationWillShowDelegate)(const char* notification);
66
69
  - (instancetype) init {
67
70
  if (self = [super init]) {
68
71
  [OneSignal.Notifications addPermissionObserver:self];
72
+ [OneSignal.Notifications addForegroundLifecycleListener:self];
73
+ [OneSignal.Notifications addClickListener:self];
69
74
  }
70
75
 
71
76
  return self;
72
77
  }
73
78
 
74
- - (void)onOSPermissionChanged:(OSPermissionState*)state {
79
+ - (void)onNotificationPermissionDidChange:(BOOL)permission {
75
80
  if (_permissionDelegate != nil) {
76
- auto curr = jsonStringFromDictionary([state jsonRepresentation]);
77
- _permissionDelegate(curr);
81
+ _permissionDelegate(permission);
82
+ }
83
+ }
84
+
85
+ - (void)onWillDisplayNotification:(OSNotificationWillDisplayEvent *)event {
86
+ if (_willDisplayDelegate != nil) {
87
+ NSString *stringNotification = [event.notification stringify];
88
+ _willDisplayDelegate([stringNotification UTF8String]);
89
+
90
+ _willDisplayEvents[event.notification.notificationId] = event;
91
+ }
92
+ }
93
+
94
+ - (void)notificationsWillDisplayEventPreventDefault:(NSString *)notificationId {
95
+ OSNotificationWillDisplayEvent *event = _willDisplayEvents[notificationId];
96
+ [event preventDefault];
97
+ }
98
+
99
+ - (void)notificationsDisplay:(NSString *)notificationId {
100
+ OSNotificationWillDisplayEvent *event = _willDisplayEvents[notificationId];
101
+ [event.notification display];
102
+ }
103
+
104
+ - (void)onClickNotification:(OSNotificationClickEvent * _Nonnull)event {
105
+ if (_clickDelegate != nil) {
106
+ NSString *stringNotification = [event.notification stringify];
107
+ NSString *stringResultActionId = event.result.actionId;
108
+ NSString *stringResultUrl = event.result.url;
109
+ _clickDelegate([stringNotification UTF8String], [stringResultActionId UTF8String], [stringResultUrl UTF8String]);
78
110
  }
79
111
  }
80
112
 
@@ -89,9 +121,13 @@ extern "C" {
89
121
  return [OneSignal.Notifications permission];
90
122
  }
91
123
 
92
- /*bool _notificationsGetCanRequestPermission() {
124
+ bool _notificationsGetCanRequestPermission() {
93
125
  return [OneSignal.Notifications canRequestPermission];
94
- }*/
126
+ }
127
+
128
+ int _notificationsGetPermissionNative() {
129
+ return [OneSignal.Notifications permissionNative];
130
+ }
95
131
 
96
132
  void _notificationsClearAll() {
97
133
  [OneSignal.Notifications clearAll];
@@ -103,22 +139,25 @@ extern "C" {
103
139
  } fallbackToSettings:fallbackToSettings];
104
140
  }
105
141
 
106
- void _notificationsAddPermissionStateChangedCallback(StateListenerDelegate callback) {
142
+ void _notificationsAddPermissionObserver(PermissionListenerDelegate callback) {
107
143
  [[OneSignalNotificationsObserver sharedNotificationsObserver] setPermissionDelegate:callback];
108
144
  }
109
145
 
110
- void _notificationsSetWillShowHandler(NotificationWillShowDelegate callback) {
111
- [OneSignal.Notifications setNotificationWillShowInForegroundHandler:^(OSNotification *notification, OSNotificationDisplayResponse completion) {
112
- NSString *stringResponse = [notification stringify];
113
- bool shouldDisplay = callback([stringResponse UTF8String]);
114
- completion(shouldDisplay ? notification : nil);
115
- }];
146
+ void _notificationsSetForegroundWillDisplayCallback(WillDisplayListenerDelegate callback) {
147
+ [[OneSignalNotificationsObserver sharedNotificationsObserver] setWillDisplayDelegate:callback];
148
+ }
149
+
150
+ void _notificationsWillDisplayEventPreventDefault(const char* notifcationId) {
151
+ NSString *key = [NSString stringWithUTF8String:notifcationId];
152
+ [[OneSignalNotificationsObserver sharedNotificationsObserver] notificationsWillDisplayEventPreventDefault:key];
153
+ }
154
+
155
+ void _notificationsDisplay(const char* notifcationId) {
156
+ NSString *key = [NSString stringWithUTF8String:notifcationId];
157
+ [[OneSignalNotificationsObserver sharedNotificationsObserver] notificationsDisplay:key];
116
158
  }
117
159
 
118
- void _notificationsSetOpenedHandler(StringListenerDelegate callback) {
119
- [OneSignal.Notifications setNotificationOpenedHandler:^(OSNotificationOpenedResult * _Nonnull result) {
120
- NSString *stringResponse = [result stringify];
121
- callback([stringResponse UTF8String]);
122
- }];
160
+ void _notificationsSetClickCallback(ClickListenerDelegate callback) {
161
+ [[OneSignalNotificationsObserver sharedNotificationsObserver] setClickDelegate:callback];
123
162
  }
124
163
  }
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * Modified MIT License
3
3
  *
4
- * Copyright 2022 OneSignal
4
+ * Copyright 2023 OneSignal
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  * of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * Modified MIT License
3
3
  *
4
- * Copyright 2022 OneSignal
4
+ * Copyright 2023 OneSignal
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  * of this software and associated documentation files (the "Software"), to deal
@@ -38,18 +38,6 @@ typedef void (*StateListenerDelegate)(const char* current, const char* previous)
38
38
 
39
39
  #define TO_NSSTRING(cstr) cstr ? [NSString stringWithUTF8String:cstr] : nil
40
40
 
41
- template <typename TObj>
42
- TObj objFromJsonString2(const char* jsonString) {
43
- NSData* jsonData = [[NSString stringWithUTF8String:jsonString] dataUsingEncoding:NSUTF8StringEncoding];
44
- NSError* error = nil;
45
- TObj arr = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
46
-
47
- if (error != nil)
48
- return nil;
49
-
50
- return arr;
51
- }
52
-
53
41
  /*
54
42
  * Observer singleton for global callbacks
55
43
  */
@@ -80,10 +68,10 @@ TObj objFromJsonString2(const char* jsonString) {
80
68
  return self;
81
69
  }
82
70
 
83
- - (void)onOSPushSubscriptionChangedWithStateChanges:(OSPushSubscriptionStateChanges*)stateChanges {
71
+ - (void)onPushSubscriptionDidChangeWithState:(OSPushSubscriptionChangedState*)state {
84
72
  if (_pushSubscriptionDelegate != nil) {
85
- auto curr = jsonStringFromDictionary([[stateChanges to] jsonRepresentation]);
86
- auto prev = jsonStringFromDictionary([[stateChanges from] jsonRepresentation]);
73
+ auto curr = jsonStringFromDictionary([[state current] jsonRepresentation]);
74
+ auto prev = jsonStringFromDictionary([[state previous] jsonRepresentation]);
87
75
  _pushSubscriptionDelegate(curr, prev);
88
76
  }
89
77
  }
@@ -99,17 +87,13 @@ extern "C" {
99
87
  [OneSignal.User setLanguage:TO_NSSTRING(languageCode)];
100
88
  }
101
89
 
102
- /*id<OSPushSubscription> _userGetPushSubscription() {
103
- return OneSignal.User.pushSubscription;
104
- }*/
105
-
106
90
  void _userAddAlias(const char* aliasLabel, const char* aliasId) {
107
91
  [OneSignal.User addAliasWithLabel:TO_NSSTRING(aliasLabel)
108
92
  id:TO_NSSTRING(aliasId)];
109
93
  }
110
94
 
111
95
  void _userAddAliases(const char* aliasesJson) {
112
- NSDictionary *aliases = objFromJsonString2<NSDictionary*>(aliasesJson);
96
+ NSDictionary *aliases = dictionaryFromJsonString(aliasesJson);
113
97
 
114
98
  [OneSignal.User addAliases:aliases];
115
99
  }
@@ -119,7 +103,7 @@ extern "C" {
119
103
  }
120
104
 
121
105
  void _userRemoveAliases(const char* aliasesJson) {
122
- NSArray *aliases = objFromJsonString2<NSArray*>(aliasesJson);
106
+ NSArray *aliases = arrayFromJsonString(aliasesJson);
123
107
 
124
108
  if (aliases == nil) {
125
109
  NSLog(@"[Onesignal] Could not parse aliases to delete");
@@ -151,7 +135,7 @@ extern "C" {
151
135
  }
152
136
 
153
137
  void _userAddTags(const char* tagsJson) {
154
- NSDictionary *tags = objFromJsonString2<NSDictionary*>(tagsJson);
138
+ NSDictionary *tags = dictionaryFromJsonString(tagsJson);
155
139
 
156
140
  [OneSignal.User addTags:tags];
157
141
  }
@@ -161,7 +145,7 @@ extern "C" {
161
145
  }
162
146
 
163
147
  void _userRemoveTags(const char* tagsJson) {
164
- NSArray *tags = objFromJsonString2<NSArray*>(tagsJson);
148
+ NSArray *tags = arrayFromJsonString(tagsJson);
165
149
 
166
150
  if (tags == nil) {
167
151
  NSLog(@"[Onesignal] Could not parse tags to delete");
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * Modified MIT License
3
3
  *
4
- * Copyright 2022 OneSignal
4
+ * Copyright 2023 OneSignal
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  * of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * Modified MIT License
3
3
  *
4
- * Copyright 2022 OneSignal
4
+ * Copyright 2023 OneSignal
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  * of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * Modified MIT License
3
3
  *
4
- * Copyright 2022 OneSignal
4
+ * Copyright 2023 OneSignal
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  * of this software and associated documentation files (the "Software"), to deal
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * Modified MIT License
3
3
  *
4
- * Copyright 2022 OneSignal
4
+ * Copyright 2023 OneSignal
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  * of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,41 @@
1
+ /*
2
+ * Modified MIT License
3
+ *
4
+ * Copyright 2023 OneSignal
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * 1. The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * 2. All copies of substantial portions of the Software may only be used in connection
17
+ * with services provided by OneSignal.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ * THE SOFTWARE.
26
+ */
27
+
28
+ using System;
29
+ using UnityEngine;
30
+ using System.Runtime.InteropServices;
31
+ using OneSignalSDK.Notifications.Internal;
32
+ using OneSignalSDK.Notifications.Models;
33
+
34
+ namespace OneSignalSDK.iOS.Notifications.Models {
35
+ public sealed class iOSDisplayableNotification : Notification, IDisplayableNotification {
36
+ [DllImport("__Internal")] private static extern void _notificationsDisplay(string notificationId);
37
+
38
+ public void Display()
39
+ => _notificationsDisplay(this.NotificationId);
40
+ }
41
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 6e6793593f96f42a498eb244efe9895a
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * Modified MIT License
3
3
  *
4
- * Copyright 2022 OneSignal
4
+ * Copyright 2023 OneSignal
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  * of this software and associated documentation files (the "Software"), to deal
@@ -27,10 +27,12 @@
27
27
 
28
28
 
29
29
  using UnityEngine;
30
+ using System;
30
31
  using System.Collections.Generic;
31
32
  using System.Runtime.InteropServices;
32
33
  using OneSignalSDK.InAppMessages;
33
34
  using OneSignalSDK.InAppMessages.Models;
35
+ using OneSignalSDK.InAppMessages.Internal;
34
36
 
35
37
  namespace OneSignalSDK.iOS.InAppMessages {
36
38
  internal sealed class iOSInAppMessagesManager : IInAppMessagesManager {
@@ -38,7 +40,7 @@ namespace OneSignalSDK.iOS.InAppMessages {
38
40
  [DllImport("__Internal")] private static extern void _inAppMessagesSetDidDisplayCallback(StringListenerDelegate callback);
39
41
  [DllImport("__Internal")] private static extern void _inAppMessagesSetWillDismissCallback(StringListenerDelegate callback);
40
42
  [DllImport("__Internal")] private static extern void _inAppMessagesSetDidDismissCallback(StringListenerDelegate callback);
41
- [DllImport("__Internal")] private static extern void _inAppMessagesSetClickedCallback(StringListenerDelegate callback);
43
+ [DllImport("__Internal")] private static extern void _inAppMessagesSetClickCallback(ClickListenerDelegate callback);
42
44
 
43
45
  [DllImport("__Internal")] private static extern void _inAppMessagesSetPaused(bool paused);
44
46
  [DllImport("__Internal")] private static extern bool _inAppMessagesGetPaused();
@@ -49,13 +51,13 @@ namespace OneSignalSDK.iOS.InAppMessages {
49
51
  [DllImport("__Internal")] private static extern void _inAppMessagesClearTriggers();
50
52
 
51
53
  private delegate void StringListenerDelegate(string response);
54
+ private delegate void ClickListenerDelegate(string message, string result, int urlType);
52
55
 
53
- public event InAppMessageLifecycleDelegate WillDisplay;
54
- public event InAppMessageLifecycleDelegate DidDisplay;
55
- public event InAppMessageLifecycleDelegate WillDismiss;
56
- public event InAppMessageLifecycleDelegate DidDismiss;
57
-
58
- public event InAppMessageClickedDelegate Clicked;
56
+ public event EventHandler<InAppMessageWillDisplayEventArgs> WillDisplay;
57
+ public event EventHandler<InAppMessageDidDisplayEventArgs> DidDisplay;
58
+ public event EventHandler<InAppMessageWillDismissEventArgs> WillDismiss;
59
+ public event EventHandler<InAppMessageDidDismissEventArgs> DidDismiss;
60
+ public event EventHandler<InAppMessageClickEventArgs> Clicked;
59
61
 
60
62
  private static iOSInAppMessagesManager _instance;
61
63
 
@@ -68,10 +70,10 @@ namespace OneSignalSDK.iOS.InAppMessages {
68
70
  set => _inAppMessagesSetPaused(value);
69
71
  }
70
72
 
71
- public void AddTrigger(string key, object value)
72
- => _inAppMessagesAddTrigger(key, value.ToString()); // test
73
+ public void AddTrigger(string key, string value)
74
+ => _inAppMessagesAddTrigger(key, value.ToString());
73
75
 
74
- public void AddTriggers(Dictionary<string, object> triggers) // <string, string> to <string, object>
76
+ public void AddTriggers(Dictionary<string, string> triggers)
75
77
  => _inAppMessagesAddTriggers(Json.Serialize(triggers));
76
78
 
77
79
  public void RemoveTrigger(string key)
@@ -88,31 +90,86 @@ namespace OneSignalSDK.iOS.InAppMessages {
88
90
  _inAppMessagesSetDidDisplayCallback(_onDidDisplay);
89
91
  _inAppMessagesSetWillDismissCallback(_onWillDismiss);
90
92
  _inAppMessagesSetDidDismissCallback(_onDidDismiss);
91
- _inAppMessagesSetClickedCallback(_onClicked);
93
+ _inAppMessagesSetClickCallback(_onClicked);
92
94
  }
93
95
 
94
96
  [AOT.MonoPInvokeCallback(typeof(StringListenerDelegate))]
95
- private static void _onWillDisplay(string response)
96
- => UnityMainThreadDispatch.Post(state => _instance.WillDisplay?.Invoke(new InAppMessage { messageId = response }));
97
+ private static void _onWillDisplay(string response) {
98
+ var message = new InAppMessage(response);
99
+ InAppMessageWillDisplayEventArgs args = new InAppMessageWillDisplayEventArgs(message);
100
+
101
+ EventHandler<InAppMessageWillDisplayEventArgs> handler = _instance.WillDisplay;
102
+ if (handler != null)
103
+ {
104
+ UnityMainThreadDispatch.Post(state => handler(_instance, args));
105
+ }
106
+ }
97
107
 
98
108
  [AOT.MonoPInvokeCallback(typeof(StringListenerDelegate))]
99
- private static void _onDidDisplay(string response)
100
- => UnityMainThreadDispatch.Post(state => _instance.DidDisplay?.Invoke(new InAppMessage { messageId = response }));
109
+ private static void _onDidDisplay(string response) {
110
+ var message = new InAppMessage(response);
111
+ InAppMessageDidDisplayEventArgs args = new InAppMessageDidDisplayEventArgs(message);
112
+
113
+ EventHandler<InAppMessageDidDisplayEventArgs> handler = _instance.DidDisplay;
114
+ if (handler != null)
115
+ {
116
+ UnityMainThreadDispatch.Post(state => handler(_instance, args));
117
+ }
118
+ }
101
119
 
102
120
  [AOT.MonoPInvokeCallback(typeof(StringListenerDelegate))]
103
- private static void _onWillDismiss(string response)
104
- => UnityMainThreadDispatch.Post(state => _instance.WillDismiss?.Invoke(new InAppMessage { messageId = response }));
121
+ private static void _onWillDismiss(string response) {
122
+ var message = new InAppMessage(response);
123
+ InAppMessageWillDismissEventArgs args = new InAppMessageWillDismissEventArgs(message);
124
+
125
+ EventHandler<InAppMessageWillDismissEventArgs> handler = _instance.WillDismiss;
126
+ if (handler != null)
127
+ {
128
+ UnityMainThreadDispatch.Post(state => handler(_instance, args));
129
+ }
130
+ }
105
131
 
106
132
  [AOT.MonoPInvokeCallback(typeof(StringListenerDelegate))]
107
- private static void _onDidDismiss(string response)
108
- => UnityMainThreadDispatch.Post(state => _instance.DidDismiss?.Invoke(new InAppMessage { messageId = response }));
109
-
110
- [AOT.MonoPInvokeCallback(typeof(StringListenerDelegate))] // iOS returns InAppMessageAction. Android returns InAppMessageClickedResult
111
- private static void _onClicked(string response) {
112
- InAppMessageClickedResult temp = new InAppMessageClickedResult();
113
- temp.action = JsonUtility.FromJson<InAppMessageAction>(response);
114
- //temp.message = new InAppMessage { messageId = "messageIdTemp" };
115
- UnityMainThreadDispatch.Post(state => _instance.Clicked?.Invoke(temp));
133
+ private static void _onDidDismiss(string response) {
134
+ var message = new InAppMessage(response);
135
+ InAppMessageDidDismissEventArgs args = new InAppMessageDidDismissEventArgs(message);
136
+
137
+ EventHandler<InAppMessageDidDismissEventArgs> handler = _instance.DidDismiss;
138
+ if (handler != null)
139
+ {
140
+ UnityMainThreadDispatch.Post(state => handler(_instance, args));
141
+ }
142
+ }
143
+
144
+ [AOT.MonoPInvokeCallback(typeof(ClickListenerDelegate))]
145
+ private static void _onClicked(string message, string result, int urlType) {
146
+ var mes = JsonUtility.FromJson<InAppMessage>(message);
147
+ var res = JsonUtility.FromJson<InAppMessageClickResult>(result);
148
+
149
+ var urlTarget = IntToInAppMessageActionUrlType(urlType);
150
+ var clickRes = new InAppMessageClickResult(res.ActionId, urlTarget, res.Url, res.ClosingMessage);
151
+
152
+ InAppMessageClickEventArgs args = new InAppMessageClickEventArgs(mes, clickRes);
153
+
154
+ EventHandler<InAppMessageClickEventArgs> handler = _instance.Clicked;
155
+ if (handler != null)
156
+ {
157
+ UnityMainThreadDispatch.Post(state => handler(_instance, args));
158
+ }
159
+ }
160
+
161
+ public static InAppMessageActionUrlType IntToInAppMessageActionUrlType(int urlType) {
162
+ switch (urlType)
163
+ {
164
+ case 0:
165
+ return InAppMessageActionUrlType.Browser;
166
+ case 1:
167
+ return InAppMessageActionUrlType.InAppWebview;
168
+ case 2:
169
+ return InAppMessageActionUrlType.RepalceContent;
170
+ default:
171
+ return null;
172
+ }
116
173
  }
117
174
  }
118
175
  }
@@ -0,0 +1,56 @@
1
+ /*
2
+ * Modified MIT License
3
+ *
4
+ * Copyright 2023 OneSignal
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * 1. The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * 2. All copies of substantial portions of the Software may only be used in connection
17
+ * with services provided by OneSignal.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ * THE SOFTWARE.
26
+ */
27
+
28
+ using System.Threading.Tasks;
29
+ using System.Runtime.InteropServices;
30
+ using OneSignalSDK.LiveActivities;
31
+ using OneSignalSDK.iOS.Utilities;
32
+
33
+ namespace OneSignalSDK.iOS.LiveActivities {
34
+ internal sealed class iOSLiveActivitiesManager : ILiveActivitiesManager {
35
+ [DllImport("__Internal")] private static extern void _enterLiveActivity(string activityId, string token, int hashCode, BooleanResponseDelegate callback);
36
+ [DllImport("__Internal")] private static extern void _exitLiveActivity(string activityId, int hashCode, BooleanResponseDelegate callback);
37
+
38
+ private delegate void BooleanResponseDelegate(int hashCode, bool response);
39
+
40
+ public async Task<bool> EnterAsync(string activityId, string token) {
41
+ var (proxy, hashCode) = WaitingProxy._setupProxy<bool>();
42
+ _enterLiveActivity(activityId, token, hashCode, BooleanCallbackProxy);
43
+ return await proxy;
44
+ }
45
+
46
+ public async Task<bool> ExitAsync(string activityId) {
47
+ var (proxy, hashCode) = WaitingProxy._setupProxy<bool>();
48
+ _exitLiveActivity(activityId, hashCode, BooleanCallbackProxy);
49
+ return await proxy;
50
+ }
51
+
52
+ [AOT.MonoPInvokeCallback(typeof(BooleanResponseDelegate))]
53
+ private static void BooleanCallbackProxy(int hashCode, bool response)
54
+ => WaitingProxy.ResolveCallbackProxy(hashCode, response);
55
+ }
56
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: a0831e8d503194992a290b893af97a6a
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * Modified MIT License
3
3
  *
4
- * Copyright 2022 OneSignal
4
+ * Copyright 2023 OneSignal
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  * of this software and associated documentation files (the "Software"), to deal
@@ -41,7 +41,7 @@ namespace OneSignalSDK.iOS.Location {
41
41
  set => _locationSetIsShared(value);
42
42
  }
43
43
 
44
- public void RequestPermission() { // iOS make async
44
+ public void RequestPermission() {
45
45
  _locationRequestPermission();
46
46
  }
47
47
  }