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

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.
@@ -1,5 +1,5 @@
1
1
  <dependencies>
2
2
  <iosPods>
3
- <iosPod name="OneSignalXCFramework" version="5.0.0-beta-02" addToAllTargets="true" />
3
+ <iosPod name="OneSignalXCFramework" version="5.0.0-beta-04" addToAllTargets="true" />
4
4
  </iosPods>
5
5
  </dependencies>
@@ -25,18 +25,11 @@
25
25
  * THE SOFTWARE.
26
26
  */
27
27
 
28
- using System.Collections.Generic;
28
+ using UnityEngine;
29
29
  using System.Linq;
30
30
  using System.Threading.Tasks;
31
- using UnityEngine;
31
+ using System.Collections.Generic;
32
32
  using System.Runtime.InteropServices;
33
- using OneSignalSDK.iOS.Notifications;
34
- using OneSignalSDK.iOS.InAppMessages;
35
- using OneSignalSDK.iOS.Debug;
36
- using OneSignalSDK.iOS.Location;
37
- using OneSignalSDK.iOS.Session;
38
- using OneSignalSDK.iOS.User;
39
- using OneSignalSDK.iOS.Utilities;
40
33
  using OneSignalSDK.Notifications;
41
34
  using OneSignalSDK.InAppMessages;
42
35
  using OneSignalSDK.Debug;
@@ -44,22 +37,24 @@ using OneSignalSDK.Debug.Utilities;
44
37
  using OneSignalSDK.Location;
45
38
  using OneSignalSDK.Session;
46
39
  using OneSignalSDK.User;
40
+ using OneSignalSDK.LiveActivities;
41
+ using OneSignalSDK.iOS.Notifications;
42
+ using OneSignalSDK.iOS.InAppMessages;
43
+ using OneSignalSDK.iOS.Debug;
44
+ using OneSignalSDK.iOS.Location;
45
+ using OneSignalSDK.iOS.Session;
46
+ using OneSignalSDK.iOS.User;
47
+ using OneSignalSDK.iOS.LiveActivities;
47
48
 
48
49
  namespace OneSignalSDK.iOS {
49
- public sealed partial class OneSignaliOS : OneSignal {
50
- [DllImport("__Internal")] private static extern bool _getPrivacyConsent();
51
- [DllImport("__Internal")] private static extern void _setPrivacyConsent(bool consent);
52
- [DllImport("__Internal")] private static extern bool _getRequiresPrivacyConsent();
53
- [DllImport("__Internal")] private static extern void _setRequiresPrivacyConsent(bool required);
50
+ public sealed partial class OneSignaliOS : OneSignalPlatform {
51
+ [DllImport("__Internal")] private static extern void _setConsentGiven(bool consent);
52
+ [DllImport("__Internal")] private static extern void _setConsentRequired(bool required);
54
53
  [DllImport("__Internal")] private static extern void _setLaunchURLsInApp(bool launchInApp);
55
54
  [DllImport("__Internal")] private static extern void _initialize(string appId);
56
55
  [DllImport("__Internal")] private static extern void _login(string externalId);
57
56
  [DllImport("__Internal")] private static extern void _loginWithJwtBearerToken(string externalId, string jwtBearerToken);
58
57
  [DllImport("__Internal")] private static extern void _logout();
59
- [DllImport("__Internal")] private static extern void _enterLiveActivity(string activityId, string token, int hashCode, BooleanResponseDelegate callback);
60
- [DllImport("__Internal")] private static extern void _exitLiveActivity(string activityId, int hashCode, BooleanResponseDelegate callback);
61
-
62
- private delegate void BooleanResponseDelegate(int hashCode, bool response);
63
58
 
64
59
  private iOSUserManager _user;
65
60
  private iOSSessionManager _session;
@@ -67,6 +62,7 @@ namespace OneSignalSDK.iOS {
67
62
  private iOSLocationManager _location;
68
63
  private iOSInAppMessagesManager _inAppMessages;
69
64
  private iOSDebugManager _debug;
65
+ private iOSLiveActivitiesManager _liveActivities;
70
66
 
71
67
  private static OneSignaliOS _instance;
72
68
 
@@ -105,14 +101,16 @@ namespace OneSignalSDK.iOS {
105
101
  get => _debug;
106
102
  }
107
103
 
108
- public override bool PrivacyConsent {
109
- get => _getPrivacyConsent();
110
- set => _setPrivacyConsent(value);
104
+ public override ILiveActivitiesManager LiveActivities {
105
+ get => _liveActivities;
111
106
  }
112
107
 
113
- public override bool RequiresPrivacyConsent {
114
- get => _getRequiresPrivacyConsent();
115
- set => _setRequiresPrivacyConsent(value);
108
+ public override bool ConsentGiven {
109
+ set => _setConsentGiven(value);
110
+ }
111
+
112
+ public override bool ConsentRequired {
113
+ set => _setConsentRequired(value);
116
114
  }
117
115
 
118
116
  public override void SetLaunchURLsInApp(bool launchInApp)
@@ -144,6 +142,10 @@ namespace OneSignalSDK.iOS {
144
142
  _session = new iOSSessionManager();
145
143
  }
146
144
 
145
+ if (_liveActivities == null) {
146
+ _liveActivities = new iOSLiveActivitiesManager();
147
+ }
148
+
147
149
  _completedInit(appId);
148
150
  }
149
151
 
@@ -158,21 +160,5 @@ namespace OneSignalSDK.iOS {
158
160
  public override void Logout() {
159
161
  _logout();
160
162
  }
161
-
162
- public override async Task<bool> EnterLiveActivity(string activityId, string token) {
163
- var (proxy, hashCode) = WaitingProxy._setupProxy<bool>();
164
- _enterLiveActivity(activityId, token, hashCode, BooleanCallbackProxy);
165
- return await proxy;
166
- }
167
-
168
- public override async Task<bool> ExitLiveActivity(string activityId) {
169
- var (proxy, hashCode) = WaitingProxy._setupProxy<bool>();
170
- _exitLiveActivity(activityId, hashCode, BooleanCallbackProxy);
171
- return await proxy;
172
- }
173
-
174
- [AOT.MonoPInvokeCallback(typeof(BooleanResponseDelegate))]
175
- private static void BooleanCallbackProxy(int hashCode, bool response)
176
- => WaitingProxy.ResolveCallbackProxy(hashCode, response);
177
163
  }
178
164
  }
@@ -34,7 +34,7 @@ namespace OneSignalSDK.iOS {
34
34
  /// </summary>
35
35
  internal static class OneSignaliOSInit {
36
36
  [RuntimeInitializeOnLoadMethod] public static void Init() {
37
- if (!OneSignal.DidInitialize)
37
+ if (!OneSignalPlatform.DidInitialize)
38
38
  OneSignal.Default = new OneSignaliOS();
39
39
  }
40
40
  }
@@ -27,9 +27,10 @@
27
27
 
28
28
  #import <UIKit/UIKit.h>
29
29
 
30
- @interface OneSignalBridgeUtil
30
+ @interface OneSignalBridgeUtil : NSObject
31
31
 
32
32
  const char* jsonStringFromDictionary(NSDictionary *dictionary);
33
- // TObj objFromJsonString(const char* jsonString);
33
+ NSDictionary* dictionaryFromJsonString(const char* jsonString);
34
+ NSArray* arrayFromJsonString(const char* jsonString);
34
35
 
35
36
  @end
@@ -28,6 +28,7 @@
28
28
  #import "OneSignalBridgeUtil.h"
29
29
 
30
30
  @implementation OneSignalBridgeUtil
31
+
31
32
  const char* jsonStringFromDictionary(NSDictionary *dictionary) {
32
33
  NSError *error;
33
34
  NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:&error];
@@ -35,15 +36,24 @@ const char* jsonStringFromDictionary(NSDictionary *dictionary) {
35
36
  return [jsonString UTF8String];
36
37
  }
37
38
 
38
- // template <typename TObj>
39
- // TObj objFromJsonString(const char* jsonString) {
40
- // NSData* jsonData = [[NSString stringWithUTF8String:jsonString] dataUsingEncoding:NSUTF8StringEncoding];
41
- // NSError* error = nil;
42
- // TObj arr = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
39
+ template <typename TObj>
40
+ TObj objFromJsonString(const char* jsonString) {
41
+ NSData* jsonData = [[NSString stringWithUTF8String:jsonString] dataUsingEncoding:NSUTF8StringEncoding];
42
+ NSError* error = nil;
43
+ TObj arr = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
44
+
45
+ if (error != nil)
46
+ return nil;
47
+
48
+ return arr;
49
+ }
43
50
 
44
- // if (error != nil)
45
- // return nil;
51
+ NSDictionary* dictionaryFromJsonString(const char* jsonString) {
52
+ return objFromJsonString<NSDictionary*>(jsonString);
53
+ }
54
+
55
+ NSArray* arrayFromJsonString(const char* jsonString) {
56
+ return objFromJsonString<NSArray*>(jsonString);
57
+ }
46
58
 
47
- // return arr;
48
- // }
49
59
  @end
@@ -29,8 +29,6 @@
29
29
  #import <OneSignalUser/OneSignalUser-Swift.h>
30
30
  #import <OneSignalFramework/OneSignalFramework.h>
31
31
 
32
- typedef void (*BooleanResponseDelegate)(int hashCode, bool response);
33
-
34
32
  /*
35
33
  * Helpers
36
34
  */
@@ -59,36 +57,15 @@ extern "C" {
59
57
  [OneSignal logout];
60
58
  }
61
59
 
62
- bool _getPrivacyConsent() {
63
- return OneSignal.getPrivacyConsent;
64
- }
65
-
66
- void _setPrivacyConsent(bool consent) {
67
- [OneSignal setPrivacyConsent:consent];
68
- }
69
-
70
- bool _getRequiresPrivacyConsent() {
71
- return [OneSignal requiresPrivacyConsent];
60
+ void _setConsentGiven(bool consent) {
61
+ [OneSignal setConsentGiven:consent];
72
62
  }
73
63
 
74
- void _setRequiresPrivacyConsent(bool required) {
75
- [OneSignal setRequiresPrivacyConsent:required];
64
+ void _setConsentRequired(bool required) {
65
+ [OneSignal setConsentRequired:required];
76
66
  }
77
67
 
78
68
  void _setLaunchURLsInApp(bool launchInApp) {
79
69
  [OneSignal setLaunchURLsInApp:launchInApp];
80
70
  }
81
-
82
- void _enterLiveActivity(const char* activityId, const char* token, int hashCode, BooleanResponseDelegate callback) {
83
- [OneSignal enterLiveActivity:TO_NSSTRING(activityId)
84
- withToken:TO_NSSTRING(token)
85
- withSuccess:^(NSDictionary *result) { CALLBACK(YES); }
86
- withFailure:^(NSError *error) { CALLBACK(NO); }];
87
- }
88
-
89
- void _exitLiveActivity(const char* activityId, int hashCode, BooleanResponseDelegate callback) {
90
- [OneSignal exitLiveActivity:TO_NSSTRING(activityId)
91
- withSuccess:^(NSDictionary *result) { CALLBACK(YES); }
92
- withFailure:^(NSError *error) { CALLBACK(NO); }];
93
- }
94
71
  }
@@ -31,6 +31,7 @@
31
31
  #import "OneSignalBridgeUtil.h"
32
32
 
33
33
  typedef void (*StringListenerDelegate)(const char* response);
34
+ typedef void (*ClickListenerDelegate)(const char* message, const char* result, int urlType);
34
35
 
35
36
  /*
36
37
  * Helpers
@@ -39,29 +40,18 @@ typedef void (*StringListenerDelegate)(const char* response);
39
40
  #define CALLBACK(value) callback(hashCode, value)
40
41
  #define TO_NSSTRING(cstr) cstr ? [NSString stringWithUTF8String:cstr] : nil
41
42
 
42
- template <typename TObj>
43
- TObj objFromJsonString(const char* jsonString) {
44
- NSData* jsonData = [[NSString stringWithUTF8String:jsonString] dataUsingEncoding:NSUTF8StringEncoding];
45
- NSError* error = nil;
46
- TObj arr = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
47
-
48
- if (error != nil)
49
- return nil;
50
-
51
- return arr;
52
- }
53
-
54
43
  /*
55
44
  * Observer singleton for global callbacks
56
45
  */
57
46
 
58
- @interface OneSignalInAppMessagesObserver : NSObject <OSInAppMessageLifecycleHandler>
47
+ @interface OneSignalInAppMessagesObserver : NSObject <OSInAppMessageLifecycleListener, OSInAppMessageClickListener>
59
48
 
60
49
  + (instancetype) sharedInAppMessagesObserver;
61
50
  @property StringListenerDelegate willDisplayDelegate;
62
51
  @property StringListenerDelegate didDisplayDelegate;
63
52
  @property StringListenerDelegate willDismissDelegate;
64
53
  @property StringListenerDelegate didDismissDelegate;
54
+ @property ClickListenerDelegate clickDelegate;
65
55
 
66
56
  @end
67
57
 
@@ -78,30 +68,39 @@ TObj objFromJsonString(const char* jsonString) {
78
68
 
79
69
  - (instancetype) init {
80
70
  if (self = [super init]) {
81
- [OneSignal.InAppMessages setLifecycleHandler:self];
71
+ [OneSignal.InAppMessages addLifecycleListener:self];
72
+ [OneSignal.InAppMessages addClickListener:self];
82
73
  }
83
74
 
84
75
  return self;
85
76
  }
86
77
 
87
- - (void)onWillDisplayInAppMessage:(OSInAppMessage *)message {
78
+ - (void)onWillDisplayInAppMessage:(OSInAppMessageWillDisplayEvent *)event {
88
79
  if (_willDisplayDelegate != nil)
89
- _willDisplayDelegate([message.messageId UTF8String]);
80
+ _willDisplayDelegate([event.message.messageId UTF8String]);
90
81
  }
91
82
 
92
- - (void)onDidDisplayInAppMessage:(OSInAppMessage *)message {
83
+ - (void)onDidDisplayInAppMessage:(OSInAppMessageDidDisplayEvent *)event {
93
84
  if (_didDisplayDelegate != nil)
94
- _didDisplayDelegate([message.messageId UTF8String]);
85
+ _didDisplayDelegate([event.message.messageId UTF8String]);
95
86
  }
96
87
 
97
- - (void)onWillDismissInAppMessage:(OSInAppMessage *)message {
88
+ - (void)onWillDismissInAppMessage:(OSInAppMessageWillDismissEvent *)event {
98
89
  if (_willDismissDelegate != nil)
99
- _willDismissDelegate([message.messageId UTF8String]);
90
+ _willDismissDelegate([event.message.messageId UTF8String]);
100
91
  }
101
92
 
102
- - (void)onDidDismissInAppMessage:(OSInAppMessage *)message {
93
+ - (void)onDidDismissInAppMessage:(OSInAppMessageDidDismissEvent *)event {
103
94
  if (_didDismissDelegate != nil)
104
- _didDismissDelegate([message.messageId UTF8String]);
95
+ _didDismissDelegate([event.message.messageId UTF8String]);
96
+ }
97
+
98
+ - (void)onClickInAppMessage:(OSInAppMessageClickEvent * _Nonnull)event {
99
+ if (_clickDelegate != nil) {
100
+ auto message = jsonStringFromDictionary([[event message] jsonRepresentation]);
101
+ auto result = jsonStringFromDictionary([[event result] jsonRepresentation]);
102
+ _clickDelegate(message, result, event.result.urlTarget);
103
+ }
105
104
  }
106
105
 
107
106
  @end
@@ -127,10 +126,8 @@ extern "C" {
127
126
  [[OneSignalInAppMessagesObserver sharedInAppMessagesObserver] setDidDismissDelegate:callback];
128
127
  }
129
128
 
130
- void _inAppMessagesSetClickedCallback(StringListenerDelegate callback) {
131
- [OneSignal.InAppMessages setClickHandler:^(OSInAppMessageAction * _Nonnull action) {
132
- callback(jsonStringFromDictionary([action jsonRepresentation]));
133
- }];
129
+ void _inAppMessagesSetClickCallback(ClickListenerDelegate callback) {
130
+ [[OneSignalInAppMessagesObserver sharedInAppMessagesObserver] setClickDelegate:callback];
134
131
  }
135
132
 
136
133
  void _inAppMessagesSetPaused(bool paused) {
@@ -146,7 +143,7 @@ extern "C" {
146
143
  }
147
144
 
148
145
  void _inAppMessagesAddTriggers(const char* triggersJson) {
149
- NSDictionary *triggers = objFromJsonString<NSDictionary*>(triggersJson);
146
+ NSDictionary *triggers = dictionaryFromJsonString(triggersJson);
150
147
 
151
148
  [OneSignal.InAppMessages addTriggers:triggers];
152
149
  }
@@ -156,7 +153,7 @@ extern "C" {
156
153
  }
157
154
 
158
155
  void _inAppMessagesRemoveTriggers(const char* triggersJson) {
159
- NSArray *triggers = objFromJsonString<NSArray*>(triggersJson);
156
+ NSArray *triggers = arrayFromJsonString(triggersJson);
160
157
 
161
158
  [OneSignal.InAppMessages removeTriggers:triggers];
162
159
  }
@@ -0,0 +1,58 @@
1
+ /*
2
+ * Modified MIT License
3
+ *
4
+ * Copyright 2022 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
+ #import <OneSignalNotifications/OneSignalNotifications.h>
29
+ #import <OneSignalUser/OneSignalUser-Swift.h>
30
+ #import <OneSignalFramework/OneSignalFramework.h>
31
+
32
+ typedef void (*BooleanResponseDelegate)(int hashCode, bool response);
33
+
34
+ /*
35
+ * Helpers
36
+ */
37
+
38
+ #define CALLBACK(value) callback(hashCode, value)
39
+ #define TO_NSSTRING(cstr) cstr ? [NSString stringWithUTF8String:cstr] : nil
40
+
41
+ /*
42
+ * Bridge methods
43
+ */
44
+
45
+ extern "C" {
46
+ void _enterLiveActivity(const char* activityId, const char* token, int hashCode, BooleanResponseDelegate callback) {
47
+ [OneSignal.LiveActivities enter:TO_NSSTRING(activityId)
48
+ withToken:TO_NSSTRING(token)
49
+ withSuccess:^(NSDictionary *result) { CALLBACK(YES); }
50
+ withFailure:^(NSError *error) { CALLBACK(NO); }];
51
+ }
52
+
53
+ void _exitLiveActivity(const char* activityId, int hashCode, BooleanResponseDelegate callback) {
54
+ [OneSignal.LiveActivities exit:TO_NSSTRING(activityId)
55
+ withSuccess:^(NSDictionary *result) { CALLBACK(YES); }
56
+ withFailure:^(NSError *error) { CALLBACK(NO); }];
57
+ }
58
+ }
@@ -0,0 +1,37 @@
1
+ fileFormatVersion: 2
2
+ guid: af87776925bf8438bba2006c390b5306
3
+ PluginImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ iconMap: {}
7
+ executionOrder: {}
8
+ defineConstraints: []
9
+ isPreloaded: 0
10
+ isOverridable: 1
11
+ isExplicitlyReferenced: 0
12
+ validateReferences: 1
13
+ platformData:
14
+ - first:
15
+ Any:
16
+ second:
17
+ enabled: 0
18
+ settings: {}
19
+ - first:
20
+ Editor: Editor
21
+ second:
22
+ enabled: 0
23
+ settings:
24
+ DefaultValueInitialized: true
25
+ - first:
26
+ iPhone: iOS
27
+ second:
28
+ enabled: 1
29
+ settings: {}
30
+ - first:
31
+ tvOS: tvOS
32
+ second:
33
+ enabled: 1
34
+ settings: {}
35
+ userData:
36
+ assetBundleName:
37
+ assetBundleVariant:
@@ -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
  }
@@ -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
  }
@@ -109,7 +97,7 @@ extern "C" {
109
97
  }
110
98
 
111
99
  void _userAddAliases(const char* aliasesJson) {
112
- NSDictionary *aliases = objFromJsonString2<NSDictionary*>(aliasesJson);
100
+ NSDictionary *aliases = dictionaryFromJsonString(aliasesJson);
113
101
 
114
102
  [OneSignal.User addAliases:aliases];
115
103
  }
@@ -119,7 +107,7 @@ extern "C" {
119
107
  }
120
108
 
121
109
  void _userRemoveAliases(const char* aliasesJson) {
122
- NSArray *aliases = objFromJsonString2<NSArray*>(aliasesJson);
110
+ NSArray *aliases = arrayFromJsonString(aliasesJson);
123
111
 
124
112
  if (aliases == nil) {
125
113
  NSLog(@"[Onesignal] Could not parse aliases to delete");
@@ -151,7 +139,7 @@ extern "C" {
151
139
  }
152
140
 
153
141
  void _userAddTags(const char* tagsJson) {
154
- NSDictionary *tags = objFromJsonString2<NSDictionary*>(tagsJson);
142
+ NSDictionary *tags = dictionaryFromJsonString(tagsJson);
155
143
 
156
144
  [OneSignal.User addTags:tags];
157
145
  }
@@ -161,7 +149,7 @@ extern "C" {
161
149
  }
162
150
 
163
151
  void _userRemoveTags(const char* tagsJson) {
164
- NSArray *tags = objFromJsonString2<NSArray*>(tagsJson);
152
+ NSArray *tags = arrayFromJsonString(tagsJson);
165
153
 
166
154
  if (tags == nil) {
167
155
  NSLog(@"[Onesignal] Could not parse tags to delete");
@@ -0,0 +1,41 @@
1
+ /*
2
+ * Modified MIT License
3
+ *
4
+ * Copyright 2022 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:
@@ -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 2022 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:
@@ -41,8 +41,9 @@ namespace OneSignalSDK.iOS.Location {
41
41
  set => _locationSetIsShared(value);
42
42
  }
43
43
 
44
- public void RequestPermission() { // iOS make async
44
+ public Task<bool> RequestPermissionAsync() { // iOS not async yet
45
45
  _locationRequestPermission();
46
+ return Task.FromResult(true);
46
47
  }
47
48
  }
48
49
  }
@@ -32,28 +32,30 @@ using System.Collections.Generic;
32
32
  using System.Runtime.InteropServices;
33
33
  using OneSignalSDK.Notifications;
34
34
  using OneSignalSDK.Notifications.Models;
35
+ using OneSignalSDK.Notifications.Internal;
35
36
  using OneSignalSDK.iOS.Utilities;
37
+ using OneSignalSDK.iOS.Notifications.Models;
36
38
 
37
39
  namespace OneSignalSDK.iOS.Notifications {
38
40
  internal sealed class iOSNotificationsManager : INotificationsManager {
39
41
  [DllImport("__Internal")] private static extern bool _notificationsGetPermission();
40
- //[DllImport("__Internal")] private static extern bool _notificationsGetCanRequestPermission(); // iOS only for now
42
+ [DllImport("__Internal")] private static extern bool _notificationsGetCanRequestPermission();
43
+ [DllImport("__Internal")] private static extern int _notificationsGetPermissionNative();
41
44
  [DllImport("__Internal")] private static extern void _notificationsRequestPermission(bool fallbackToSettings, int hashCode, BooleanResponseDelegate callback);
42
45
  [DllImport("__Internal")] private static extern void _notificationsClearAll();
43
- //[DllImport("__Internal")] private static extern void _registerForProvisionalAuthorization(); // iOS only
44
- [DllImport("__Internal")] private static extern void _notificationsAddPermissionStateChangedCallback(StateListenerDelegate callback);
45
- [DllImport("__Internal")] private static extern void _notificationsSetWillShowHandler(NotificationWillShowInForegroundDelegate callback);
46
- [DllImport("__Internal")] private static extern void _notificationsSetOpenedHandler(StringListenerDelegate callback);
47
-
48
- public delegate void StateListenerDelegate(string current);
49
-
50
- private delegate bool NotificationWillShowInForegroundDelegate(string notification);
51
- private delegate void StringListenerDelegate(string response);
46
+ [DllImport("__Internal")] private static extern void _notificationsAddPermissionObserver(PermissionListenerDelegate callback);
47
+ [DllImport("__Internal")] private static extern void _notificationsSetForegroundWillDisplayCallback(WillDisplayListenerDelegate callback);
48
+ [DllImport("__Internal")] private static extern void _notificationsWillDisplayEventPreventDefault(string notificationId);
49
+ [DllImport("__Internal")] private static extern void _notificationsSetClickCallback(ClickListenerDelegate callback);
50
+
51
+ public delegate void PermissionListenerDelegate(bool permission);
52
+ private delegate void WillDisplayListenerDelegate(string notification);
53
+ private delegate void ClickListenerDelegate(string notification, string resultActionId, string resultUrl);
52
54
  private delegate void BooleanResponseDelegate(int hashCode, bool response);
53
55
 
54
- public event NotificationWillShowDelegate WillShow;
55
- public event NotificationClickedDelegate Clicked;
56
- public event PermissionChangedDelegate PermissionChanged;
56
+ public event EventHandler<NotificationWillDisplayEventArgs> ForegroundWillDisplay;
57
+ public event EventHandler<NotificationClickEventArgs> Clicked;
58
+ public event EventHandler<NotificationPermissionChangedEventArgs> PermissionChanged;
57
59
 
58
60
  private static iOSNotificationsManager _instance;
59
61
 
@@ -65,6 +67,14 @@ namespace OneSignalSDK.iOS.Notifications {
65
67
  get => _notificationsGetPermission();
66
68
  }
67
69
 
70
+ public bool CanRequestPermission {
71
+ get => _notificationsGetCanRequestPermission();
72
+ }
73
+
74
+ public NotificationPermission PermissionNative {
75
+ get => (NotificationPermission)_notificationsGetPermissionNative();
76
+ }
77
+
68
78
  public async Task<bool> RequestPermissionAsync(bool fallbackToSettings) {
69
79
  var (proxy, hashCode) = WaitingProxy._setupProxy<bool>();
70
80
  _notificationsRequestPermission(fallbackToSettings, hashCode, BooleanCallbackProxy);
@@ -76,57 +86,76 @@ namespace OneSignalSDK.iOS.Notifications {
76
86
  }
77
87
 
78
88
  public void Initialize() {
79
- _notificationsAddPermissionStateChangedCallback(_onPermissionStateChanged);
80
- _notificationsSetWillShowHandler(_onWillShow);
81
- _notificationsSetOpenedHandler(_onOpened);
89
+ _notificationsAddPermissionObserver(_onPermissionStateChanged);
90
+ _notificationsSetForegroundWillDisplayCallback(_onForegroundWillDisplay);
91
+ _notificationsSetClickCallback(_onClicked);
82
92
  }
83
93
 
84
- [AOT.MonoPInvokeCallback(typeof(StateListenerDelegate))]
85
- private static void _onPermissionStateChanged(string current) {
86
- var curr = JsonUtility.FromJson<PermissionState>(current);
87
- UnityMainThreadDispatch.Post(state => _instance.PermissionChanged?.Invoke(curr.permission));
94
+ [AOT.MonoPInvokeCallback(typeof(PermissionListenerDelegate))]
95
+ private static void _onPermissionStateChanged(bool permission) {
96
+ NotificationPermissionChangedEventArgs args = new NotificationPermissionChangedEventArgs(permission);
97
+
98
+ EventHandler<NotificationPermissionChangedEventArgs> handler = _instance.PermissionChanged;
99
+ if (handler != null)
100
+ {
101
+ UnityMainThreadDispatch.Post(state => handler(_instance, args));
102
+ }
88
103
  }
89
104
 
90
- /// <param name="response">OSNotification</param>
91
- [AOT.MonoPInvokeCallback(typeof(NotificationWillShowInForegroundDelegate))]
92
- private static bool _onWillShow(string response) {
93
- if (_instance.WillShow == null)
94
- return true;
105
+ [AOT.MonoPInvokeCallback(typeof(WillDisplayListenerDelegate))]
106
+ private static void _onForegroundWillDisplay(string notification) {
107
+ var notif = JsonUtility.FromJson<iOSDisplayableNotification>(notification);
108
+ _fillNotifFromObj(ref notif, Json.Deserialize(notification));
109
+
110
+ InternalNotificationWillDisplayEventArgs args = new InternalNotificationWillDisplayEventArgs(notif);
95
111
 
96
- var notification = JsonUtility.FromJson<Notification>(response);
97
- _fillNotifFromObj(ref notification, Json.Deserialize(response));
112
+ EventHandler<NotificationWillDisplayEventArgs> handler = _instance.ForegroundWillDisplay;
113
+ if (handler != null)
114
+ {
115
+ // We use Send instead of Post because we need to *not* return to our caller until the
116
+ // event handlers have returned themselves. This allows a handler to call PreventDefault()
117
+ // which will get passed down to Android in InternalNotificationWillDisplayEventArgs.
118
+ UnityMainThreadDispatch.Send(state => handler(_instance, args));
119
+ }
120
+ }
98
121
 
99
- Notification resultNotif = null;
100
- // Blocks current thread using Send to wait for value to assign to resultNotif inorder to display
101
- UnityMainThreadDispatch.Send(state => { resultNotif = _instance.WillShow(notification);});
122
+ public class InternalNotificationWillDisplayEventArgs : NotificationWillDisplayEventArgs {
123
+ public InternalNotificationWillDisplayEventArgs(IDisplayableNotification notification) : base(notification) { }
102
124
 
103
- return resultNotif != null;
125
+ public override void PreventDefault() {
126
+ _notificationsWillDisplayEventPreventDefault(this.Notification.NotificationId);
127
+ }
104
128
  }
105
129
 
106
- /// <param name="response">OSNotificationOpenedResult</param>
107
- [AOT.MonoPInvokeCallback(typeof(StringListenerDelegate))]
108
- private static void _onOpened(string response) {
109
- var notifOpenResult = JsonUtility.FromJson<NotificationClickedResult>(response);
130
+ [AOT.MonoPInvokeCallback(typeof(ClickListenerDelegate))]
131
+ private static void _onClicked(string notification, string resultActionId, string resultUrl) {
132
+ var notif = JsonUtility.FromJson<iOSDisplayableNotification>(notification);
133
+ _fillNotifFromObj(ref notif, Json.Deserialize(notification));
134
+
135
+ var result = new NotificationClickResult(resultActionId, resultUrl);
136
+
137
+ NotificationClickEventArgs args = new NotificationClickEventArgs(notif, result);
110
138
 
111
- if (Json.Deserialize(response) is Dictionary<string, object> resultDict && resultDict.ContainsKey("notification"))
112
- _fillNotifFromObj(ref notifOpenResult.notification, resultDict["notification"]);
139
+ EventHandler<NotificationClickEventArgs> handler = _instance.Clicked;
140
+ if (handler != null)
141
+ {
142
+ if (OneSignalPlatform.DidInitialize)
143
+ UnityMainThreadDispatch.Post(state => handler(_instance, args));
144
+ else {
145
+ void invokeOpened(string appId) {
146
+ OneSignalPlatform.OnInitialize -= invokeOpened;
147
+ UnityMainThreadDispatch.Post(state => handler(_instance, args));
148
+ }
113
149
 
114
- if (OneSignal.DidInitialize)
115
- UnityMainThreadDispatch.Post(state => _instance.Clicked?.Invoke(notifOpenResult));
116
- else {
117
- void invokeOpened(string appId) {
118
- OneSignal.OnInitialize -= invokeOpened;
119
- UnityMainThreadDispatch.Post(state => _instance.Clicked?.Invoke(notifOpenResult));
150
+ OneSignalPlatform.OnInitialize += invokeOpened;
120
151
  }
121
-
122
- OneSignal.OnInitialize += invokeOpened;
123
152
  }
124
153
  }
125
154
 
126
- private static void _fillNotifFromObj(ref Notification notif, object notifObj) {
155
+ private static void _fillNotifFromObj(ref iOSDisplayableNotification notif, object notifObj) {
127
156
  if (!(notifObj is Dictionary<string, object> notifDict))
128
157
  return;
129
-
158
+
130
159
  if (notifDict.ContainsKey("additionalData"))
131
160
  notif.additionalData = notifDict["additionalData"] as Dictionary<string, object>;
132
161
 
@@ -137,10 +166,6 @@ namespace OneSignalSDK.iOS.Notifications {
137
166
  notif.rawPayload = Json.Serialize(payloadDict);
138
167
  }
139
168
 
140
- [Serializable] private sealed class PermissionState { // temp
141
- public bool permission;
142
- }
143
-
144
169
  [AOT.MonoPInvokeCallback(typeof(BooleanResponseDelegate))]
145
170
  private static void BooleanCallbackProxy(int hashCode, bool response)
146
171
  => WaitingProxy.ResolveCallbackProxy(hashCode, response);
@@ -29,6 +29,9 @@ using System;
29
29
  using UnityEngine;
30
30
  using System.Runtime.InteropServices;
31
31
  using OneSignalSDK.User.Models;
32
+ using OneSignalSDK.User.Internal;
33
+
34
+ using OneSignalSDK.Debug.Utilities;
32
35
 
33
36
  namespace OneSignalSDK.iOS.User.Models {
34
37
  internal sealed class iOSPushSubscription : IPushSubscription {
@@ -41,7 +44,7 @@ namespace OneSignalSDK.iOS.User.Models {
41
44
 
42
45
  public delegate void StateListenerDelegate(string current, string previous);
43
46
 
44
- public event SubscriptionChangedDelegate Changed;
47
+ public event EventHandler<PushSubscriptionChangedEventArgs> Changed;
45
48
 
46
49
  private static iOSPushSubscription _instance;
47
50
 
@@ -74,8 +77,16 @@ namespace OneSignalSDK.iOS.User.Models {
74
77
  [AOT.MonoPInvokeCallback(typeof(StateListenerDelegate))]
75
78
  private static void _onPushSubscriptionStateChanged(string current, string previous) {
76
79
  var curr = JsonUtility.FromJson<PushSubscriptionState>(current);
77
- //var prev = JsonUtility.FromJson<PushSubscriptionState>(previous);
78
- UnityMainThreadDispatch.Post(state => _instance.Changed?.Invoke(curr));
80
+ var prev = JsonUtility.FromJson<PushSubscriptionState>(previous);
81
+
82
+ PushSubscriptionChangedState state = new PushSubscriptionChangedState(prev, curr);
83
+ PushSubscriptionChangedEventArgs args = new PushSubscriptionChangedEventArgs(state);
84
+
85
+ EventHandler<PushSubscriptionChangedEventArgs> handler = _instance.Changed;
86
+ if (handler != null)
87
+ {
88
+ UnityMainThreadDispatch.Post(state => handler(_instance, args));
89
+ }
79
90
  }
80
91
  }
81
92
  }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "com.onesignal.unity.ios",
3
3
  "displayName": "OneSignal Unity SDK - iOS",
4
- "version": "5.0.0-beta.2",
4
+ "version": "5.0.0-beta.3",
5
5
  "unity": "2018.4",
6
6
  "description": "OneSignal is the market leader in customer engagement, powering mobile push, web push, email, and in-app messages.",
7
7
  "dependencies": {
8
- "com.onesignal.unity.core": "5.0.0-beta.2"
8
+ "com.onesignal.unity.core": "5.0.0-beta.3"
9
9
  },
10
10
  "keywords": [
11
11
  "push-notifications",