com.onesignal.unity.ios 3.0.0-beta.5 → 3.0.1

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.
@@ -52,12 +52,8 @@
52
52
  #define ADD_APP_GROUP
53
53
 
54
54
  using System.IO;
55
- using System;
56
55
  using UnityEditor;
57
56
  using UnityEditor.iOS.Xcode;
58
- using System.Collections.Generic;
59
- using System.Diagnostics;
60
- using System.Linq;
61
57
  using System.Text.RegularExpressions;
62
58
  using UnityEditor.Build;
63
59
  using UnityEditor.Build.Reporting;
@@ -72,22 +68,15 @@ namespace OneSignalSDK {
72
68
  public class BuildPostProcessor : IPostprocessBuildWithReport {
73
69
  private const string ServiceExtensionTargetName = "OneSignalNotificationServiceExtension";
74
70
  private const string ServiceExtensionFilename = "NotificationService.swift";
71
+ private const string DependenciesFilename = "OneSignalIOSDependencies.xml";
75
72
  private const string PackageName = "com.onesignal.unity.ios";
76
73
 
74
+ private static readonly string EditorFilesPath = Path.Combine("Packages", PackageName, "Editor");
77
75
  private static readonly string PluginLibrariesPath = Path.Combine(PackageName, "Runtime", "Plugins", "iOS");
78
76
  private static readonly string PluginFilesPath = Path.Combine("Packages", PluginLibrariesPath);
79
77
 
80
- [Flags] private enum Entitlement {
81
- None = 0,
82
- ApsEnv = 1 << 0,
83
- AppGroups = 1 << 1
84
- }
85
-
86
- private static readonly Dictionary<Entitlement, string> EntitlementKeys = new Dictionary<Entitlement, string> {
87
- [Entitlement.ApsEnv] = "aps-environment",
88
- [Entitlement.AppGroups] = "com.apple.security.application-groups"
89
- };
90
-
78
+ private readonly string _appGroupName = $"group.{PlayerSettings.applicationIdentifier}.onesignal";
79
+
91
80
  private string _outputPath;
92
81
  private string _projectPath;
93
82
 
@@ -111,29 +100,19 @@ namespace OneSignalSDK {
111
100
  _outputPath = report.summary.outputPath;
112
101
  _projectPath = PBXProject.GetPBXProjectPath(_outputPath);
113
102
  _project.ReadFromString(File.ReadAllText(_projectPath));
114
-
115
- // Add required entitlements
116
- UpdateEntitlements(Entitlement.ApsEnv | Entitlement.AppGroups);
103
+
104
+ // Turn on capabilities required by OneSignal
105
+ AddProjectCapabilities();
117
106
 
118
107
  // Add the service extension
119
108
  AddNotificationServiceExtension();
120
109
 
121
- // Reload file after changes from AddNotificationServiceExtension
122
- _project.WriteToFile(_projectPath);
123
- _project.ReadFromString(File.ReadAllText(_projectPath));
124
-
125
- // Turn on push capabilities
126
- AddPushCapability();
127
-
128
- // Ensure the Pods target has been added to the extension
129
- ExtensionAddPodsToTarget();
130
-
131
110
  // Save the project back out
132
111
  File.WriteAllText(_projectPath, _project.WriteToString());
133
112
  }
134
113
 
135
114
  /// <summary>
136
- /// Checks for existing entitlements file or creates a new one and returns the path
115
+ /// Get existing entitlements file if exists or creates a new file, adds it to the project, and returns the path
137
116
  /// </summary>
138
117
  private string GetEntitlementsPath(string targetGuid, string targetName) {
139
118
  var relativePath = _project.GetBuildPropertyForAnyConfig(targetGuid, "CODE_SIGN_ENTITLEMENTS");
@@ -144,38 +123,12 @@ namespace OneSignalSDK {
144
123
  if (File.Exists(fullPath))
145
124
  return fullPath;
146
125
  }
147
-
148
- return Path.Combine(_outputPath, targetName, $"{targetName}.entitlements");
149
- }
150
-
151
- /// <summary>
152
- /// Add or update the values of necessary entitlements
153
- /// </summary>
154
- private void UpdateEntitlements(Entitlement entitlements, string targetGuid, string targetName) {
155
- var entitlementsPath = GetEntitlementsPath(targetGuid, targetName);
126
+
127
+ var entitlementsPath = Path.Combine(_outputPath, targetName, $"{targetName}.entitlements");
128
+
129
+ // make new file
156
130
  var entitlementsPlist = new PlistDocument();
157
-
158
- var existingEntitlements = File.Exists(entitlementsPath);
159
-
160
- if (existingEntitlements)
161
- entitlementsPlist.ReadFromFile(entitlementsPath);
162
-
163
- var groupsKey = EntitlementKeys[Entitlement.AppGroups];
164
-
165
- if ((entitlements & Entitlement.AppGroups) != 0) {
166
- var groups = entitlementsPlist.root[groupsKey] == null
167
- ? entitlementsPlist.root.CreateArray(groupsKey)
168
- : entitlementsPlist.root[groupsKey].AsArray();
169
-
170
- var group = $"group.{PlayerSettings.applicationIdentifier}.onesignal";
171
- if (groups.values.All(elem => elem.AsString() != group))
172
- groups.AddString(group);
173
- }
174
-
175
131
  entitlementsPlist.WriteToFile(entitlementsPath);
176
-
177
- if (existingEntitlements)
178
- return;
179
132
 
180
133
  // Copy the entitlement file to the xcode project
181
134
  var entitlementFileName = Path.GetFileName(entitlementsPath);
@@ -184,25 +137,26 @@ namespace OneSignalSDK {
184
137
  // Add the pbx configs to include the entitlements files on the project
185
138
  _project.AddFile(relativeDestination, entitlementFileName);
186
139
  _project.SetBuildProperty(targetGuid, "CODE_SIGN_ENTITLEMENTS", relativeDestination);
140
+
141
+ return entitlementsPath;
187
142
  }
188
143
 
189
- private void UpdateEntitlements(Entitlement entitlements)
190
- => UpdateEntitlements(entitlements, _project.GetMainTargetGuid(), _project.GetMainTargetName());
191
-
192
- private void AddPushCapability(string targetGuid, string targetName) {
193
- _project.AddCapability(targetGuid, PBXCapabilityType.PushNotifications);
194
- _project.AddCapability(targetGuid, PBXCapabilityType.BackgroundModes);
144
+ /// <summary>
145
+ /// Add the required capabilities and entitlements for OneSignal
146
+ /// </summary>
147
+ private void AddProjectCapabilities() {
148
+ var targetGuid = _project.GetMainTargetGuid();
149
+ var targetName = _project.GetMainTargetName();
195
150
 
196
151
  var entitlementsPath = GetEntitlementsPath(targetGuid, targetName);
197
-
198
- // NOTE: ProjectCapabilityManager's 4th constructor param requires Unity 2019.3+
199
152
  var projCapability = new ProjectCapabilityManager(_projectPath, entitlementsPath, targetName);
153
+
200
154
  projCapability.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications);
155
+ projCapability.AddPushNotifications(false);
156
+ projCapability.AddAppGroups(new[] { _appGroupName });
157
+
201
158
  projCapability.WriteToFile();
202
159
  }
203
-
204
- private void AddPushCapability() =>
205
- AddPushCapability(_project.GetMainTargetGuid(), _project.GetMainTargetName());
206
160
 
207
161
  /// <summary>
208
162
  /// Create and add the notification extension to the project
@@ -212,8 +166,10 @@ namespace OneSignalSDK {
212
166
  // If file exists then the below has been completed before from another build
213
167
  // The below will not be updated on Append builds
214
168
  // Changes would most likely need to be made to support Append builds
215
- if (ExtensionCreatePlist(_outputPath))
169
+ if (ExtensionCreatePlist(_outputPath)) {
170
+ ExtensionAddPodsToTarget();
216
171
  return;
172
+ }
217
173
 
218
174
  var extensionGuid = _project.AddAppExtension(_project.GetMainTargetGuid(),
219
175
  ServiceExtensionTargetName,
@@ -235,7 +191,15 @@ namespace OneSignalSDK {
235
191
 
236
192
  _project.WriteToFile(_projectPath);
237
193
 
238
- UpdateEntitlements(Entitlement.AppGroups, extensionGuid, ServiceExtensionTargetName);
194
+ // add capabilities + entitlements
195
+ var entitlementsPath = GetEntitlementsPath(extensionGuid, ServiceExtensionTargetName);
196
+ var projCapability = new ProjectCapabilityManager(_projectPath, entitlementsPath, ServiceExtensionTargetName);
197
+
198
+ projCapability.AddAppGroups(new[] { _appGroupName });
199
+
200
+ projCapability.WriteToFile();
201
+
202
+ ExtensionAddPodsToTarget();
239
203
  #endif
240
204
  }
241
205
 
@@ -270,7 +234,7 @@ namespace OneSignalSDK {
270
234
  notificationServicePlist.ReadFromFile(Path.Combine(PluginFilesPath, "Info.plist"));
271
235
  notificationServicePlist.root.SetString("CFBundleShortVersionString", PlayerSettings.bundleVersion);
272
236
  notificationServicePlist.root.SetString("CFBundleVersion", PlayerSettings.iOS.buildNumber);
273
-
237
+
274
238
  notificationServicePlist.WriteToFile(plistPath);
275
239
 
276
240
  return alreadyExists;
@@ -290,7 +254,25 @@ namespace OneSignalSDK {
290
254
  if (extensionEntryRegex.IsMatch(podfile))
291
255
  return;
292
256
 
293
- podfile += $"target '{ServiceExtensionTargetName}' do\n pod 'OneSignalXCFramework', '~> 3.8.1'\nend\n";
257
+ var versionRegex = new Regex("(?<=<iosPod name=\"OneSignalXCFramework\" version=\").+(?=\" addToAllTargets=\"true\" />)");
258
+ var dependenciesFilePath = Path.Combine(EditorFilesPath, DependenciesFilename);
259
+
260
+ if (!File.Exists(dependenciesFilePath)) {
261
+ Debug.LogError($"Could not find {DependenciesFilename}");
262
+ return;
263
+ }
264
+
265
+ var dependenciesFile = File.ReadAllText(dependenciesFilePath);
266
+
267
+ if (!versionRegex.IsMatch(dependenciesFile)) {
268
+ Debug.LogError($"Could not read current iOS framework dependency version from {DependenciesFilename}");
269
+ return;
270
+ }
271
+
272
+ var version = versionRegex.Match(dependenciesFile)
273
+ .ToString();
274
+
275
+ podfile += $"target '{ServiceExtensionTargetName}' do\n pod 'OneSignalXCFramework', '{version}'\nend\n";
294
276
  File.WriteAllText(podfilePath, podfile);
295
277
  }
296
278
  }
@@ -1,5 +1,5 @@
1
1
  <dependencies>
2
2
  <iosPods>
3
- <iosPod name="OneSignalXCFramework" version="3.10.0" addToAllTargets="true" />
3
+ <iosPod name="OneSignalXCFramework" version="3.10.0" addToAllTargets="true" />
4
4
  </iosPods>
5
5
  </dependencies>
@@ -35,18 +35,12 @@ namespace OneSignalSDK {
35
35
 
36
36
  public static string GetMainTargetGuid(this PBXProject project)
37
37
  => project.GetUnityMainTargetGuid();
38
-
39
- public static string GetFrameworkGuid(this PBXProject project)
40
- => project.GetUnityFrameworkTargetGuid();
41
38
  #else
42
39
  public static string GetMainTargetName(this PBXProject project)
43
40
  => PBXProject.GetUnityTargetName();
44
41
 
45
42
  public static string GetMainTargetGuid(this PBXProject project)
46
43
  => project.TargetGuidByName(PBXProject.GetUnityTargetName());
47
-
48
- public static string GetFrameworkGuid(this PBXProject project)
49
- => GetPBXProjectTargetGuid(project);
50
44
  #endif
51
45
  }
52
46
  }
@@ -48,20 +48,24 @@ namespace OneSignalSDK {
48
48
  WaitingProxies[hashCode] = proxy;
49
49
  return (proxy, hashCode);
50
50
  }
51
-
52
- [AOT.MonoPInvokeCallback(typeof(BooleanResponseDelegate))]
53
- private static void BooleanCallbackProxy(int hashCode, bool response) {
54
- if (WaitingProxies[hashCode] is Later<bool> later)
51
+
52
+ private static void ResolveCallbackProxy<TResponse>(int hashCode, TResponse response) {
53
+ if (!WaitingProxies.ContainsKey(hashCode))
54
+ return;
55
+
56
+ if (WaitingProxies[hashCode] is Later<TResponse> later)
55
57
  later.Complete(response);
58
+
56
59
  WaitingProxies.Remove(hashCode);
57
60
  }
58
61
 
62
+ [AOT.MonoPInvokeCallback(typeof(BooleanResponseDelegate))]
63
+ private static void BooleanCallbackProxy(int hashCode, bool response)
64
+ => ResolveCallbackProxy(hashCode, response);
65
+
59
66
  [AOT.MonoPInvokeCallback(typeof(StringResponseDelegate))]
60
- private static void StringCallbackProxy(int hashCode, string response) {
61
- if (WaitingProxies[hashCode] is Later<string> later)
62
- later.Complete(response);
63
- WaitingProxies.Remove(hashCode);
64
- }
67
+ private static void StringCallbackProxy(int hashCode, string response)
68
+ => ResolveCallbackProxy(hashCode, response);
65
69
 
66
70
  /*
67
71
  * Global Callbacks
@@ -93,24 +97,38 @@ namespace OneSignalSDK {
93
97
  _instance = this;
94
98
  }
95
99
 
100
+ /// <param name="response">OSNotification</param>
96
101
  [AOT.MonoPInvokeCallback(typeof(NotificationWillShowInForegroundDelegate))]
97
102
  private static bool _onNotificationReceived(string response) {
98
103
  if (_instance.NotificationWillShow == null)
99
104
  return true;
100
105
 
101
106
  var notification = JsonUtility.FromJson<Notification>(response);
102
-
103
- if (Json.Deserialize(response) is Dictionary<string, object> notifDict && notifDict.ContainsKey("additionalData"))
104
- notification.additionalData = notifDict["additionalData"] as Dictionary<string, object>;
107
+ _fillNotifFromObj(ref notification, Json.Deserialize(response));
105
108
 
106
109
  var resultNotif = _instance.NotificationWillShow(notification);
107
-
108
110
  return resultNotif != null;
109
111
  }
110
112
 
113
+ /// <param name="response">OSNotificationOpenedResult</param>
111
114
  [AOT.MonoPInvokeCallback(typeof(StringListenerDelegate))]
112
- private static void _onNotificationOpened(string response)
113
- => _instance.NotificationOpened?.Invoke(JsonUtility.FromJson<NotificationOpenedResult>(response));
115
+ private static void _onNotificationOpened(string response) {
116
+ var notifOpenResult = JsonUtility.FromJson<NotificationOpenedResult>(response);
117
+
118
+ if (Json.Deserialize(response) is Dictionary<string, object> resultDict && resultDict.ContainsKey("notification"))
119
+ _fillNotifFromObj(ref notifOpenResult.notification, resultDict["notification"]);
120
+
121
+ if (DidInitialize)
122
+ _instance.NotificationOpened?.Invoke(notifOpenResult);
123
+ else {
124
+ void invokeOpened(string appId) {
125
+ OnInitialize -= invokeOpened;
126
+ _instance.NotificationOpened?.Invoke(notifOpenResult);
127
+ }
128
+
129
+ OnInitialize += invokeOpened;
130
+ }
131
+ }
114
132
 
115
133
  [AOT.MonoPInvokeCallback(typeof(StringListenerDelegate))]
116
134
  private static void _onInAppMessageWillDisplay(string response)
@@ -134,19 +152,8 @@ namespace OneSignalSDK {
134
152
 
135
153
  [AOT.MonoPInvokeCallback(typeof(StateListenerDelegate))]
136
154
  private static void _onPermissionStateChanged(string current, string previous) {
137
- if (!(Json.Deserialize(current) is Dictionary<string, object> currState)) {
138
- SDKDebug.Error("Could not deserialize current permission state");
139
- return;
140
- }
141
-
142
- if (!(Json.Deserialize(previous) is Dictionary<string, object> prevState)) {
143
- SDKDebug.Error("Could not deserialize previous permission state");
144
- return;
145
- }
146
-
147
- var curr = (NotificationPermission)currState["status"];
148
- var prev = (NotificationPermission)prevState["status"];
149
-
155
+ var curr = JsonUtility.FromJson<NotificationPermissionState>(current);
156
+ var prev = JsonUtility.FromJson<NotificationPermissionState>(previous);
150
157
  _instance.NotificationPermissionChanged?.Invoke(curr, prev);
151
158
  }
152
159
 
@@ -28,9 +28,6 @@
28
28
  using System.Runtime.InteropServices;
29
29
 
30
30
  namespace OneSignalSDK {
31
- /// <summary>
32
- ///
33
- /// </summary>
34
31
  public sealed partial class OneSignalIOS : OneSignal {
35
32
  /*
36
33
  * Global callbacks
@@ -61,8 +58,10 @@ namespace OneSignalSDK {
61
58
  [DllImport("__Internal")] private static extern bool _getPrivacyConsent();
62
59
  [DllImport("__Internal")] private static extern void _setRequiresPrivacyConsent(bool required);
63
60
  [DllImport("__Internal")] private static extern bool _getRequiresPrivacyConsent();
61
+ [DllImport("__Internal")] private static extern void _setLaunchURLsInApp(bool launchInApp);
64
62
  [DllImport("__Internal")] private static extern void _initialize(string appId);
65
63
  [DllImport("__Internal")] private static extern void _promptForPushNotificationsWithUserResponse(int hashCode, BooleanResponseDelegate callback);
64
+ [DllImport("__Internal")] private static extern void _disablePush(bool disable);
66
65
  [DllImport("__Internal")] private static extern void _postNotification(string optionsJson, int hashCode, StringResponseDelegate callback);
67
66
  [DllImport("__Internal")] private static extern void _setTrigger(string key, string value);
68
67
  [DllImport("__Internal")] private static extern void _setTriggers(string triggersJson);
@@ -83,6 +82,7 @@ namespace OneSignalSDK {
83
82
  [DllImport("__Internal")] private static extern void _setEmail(string email, string authHash, int hashCode, BooleanResponseDelegate callback);
84
83
  [DllImport("__Internal")] private static extern void _setSMSNumber(string smsNumber, string authHash, int hashCode, BooleanResponseDelegate callback);
85
84
 
85
+ [DllImport("__Internal")] private static extern void _removeExternalUserId(int hashCode, BooleanResponseDelegate callback);
86
86
  [DllImport("__Internal")] private static extern void _logoutEmail(int hashCode, BooleanResponseDelegate callback);
87
87
  [DllImport("__Internal")] private static extern void _logoutSMSNumber(int hashCode, BooleanResponseDelegate callback);
88
88
 
@@ -0,0 +1,96 @@
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 System.Collections.Generic;
30
+ using UnityEngine;
31
+
32
+ namespace OneSignalSDK {
33
+ public sealed partial class OneSignalIOS : OneSignal {
34
+ [Serializable] private sealed class DeviceState {
35
+ public long notificationPermissionStatus;
36
+
37
+ public string userId;
38
+ public string pushToken;
39
+ public bool isSubscribed;
40
+ public bool isPushDisabled;
41
+
42
+ public string emailUserId;
43
+ public string emailAddress;
44
+ public bool isEmailSubscribed;
45
+
46
+ public string smsUserId;
47
+ public string smsNumber;
48
+ public bool isSMSSubscribed;
49
+
50
+ public static implicit operator PushSubscriptionState(DeviceState source)
51
+ => new PushSubscriptionState {
52
+ userId = source.userId,
53
+ pushToken = source.pushToken,
54
+ isSubscribed = source.isSubscribed,
55
+ isPushDisabled = source.isPushDisabled,
56
+ };
57
+
58
+ public static implicit operator EmailSubscriptionState(DeviceState source)
59
+ => new EmailSubscriptionState {
60
+ emailUserId = source.emailUserId,
61
+ emailAddress = source.emailAddress,
62
+ isSubscribed = source.isEmailSubscribed,
63
+ };
64
+
65
+ public static implicit operator SMSSubscriptionState(DeviceState source)
66
+ => new SMSSubscriptionState {
67
+ smsUserId = source.smsUserId,
68
+ smsNumber = source.smsNumber,
69
+ isSubscribed = source.isSMSSubscribed,
70
+ };
71
+ }
72
+
73
+ [Serializable] private sealed class NotificationPermissionState {
74
+ public long status;
75
+ public bool provisional;
76
+ public bool hasPrompted;
77
+
78
+ public static implicit operator NotificationPermission(NotificationPermissionState source)
79
+ => (NotificationPermission)source.status;
80
+ }
81
+
82
+ private static void _fillNotifFromObj(ref Notification notif, object notifObj) {
83
+ if (!(notifObj is Dictionary<string, object> notifDict))
84
+ return;
85
+
86
+ if (notifDict.ContainsKey("additionalData"))
87
+ notif.additionalData = notifDict["additionalData"] as Dictionary<string, object>;
88
+
89
+ if (notifDict.ContainsKey("attachments"))
90
+ notif.attachments = notifDict["attachments"] as Dictionary<string, object>;
91
+
92
+ if (notifDict.ContainsKey("rawPayload") && notifDict["rawPayload"] is Dictionary<string, object> payloadDict)
93
+ notif.rawPayload = Json.Serialize(payloadDict);
94
+ }
95
+ }
96
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 60256e1ba9474730ac255a1e9da4ce74
3
+ timeCreated: 1643996576
@@ -28,6 +28,7 @@
28
28
  using System.Collections.Generic;
29
29
  using System.Linq;
30
30
  using System.Threading.Tasks;
31
+ using UnityEngine;
31
32
 
32
33
  namespace OneSignalSDK {
33
34
  public sealed partial class OneSignalIOS : OneSignal {
@@ -45,61 +46,19 @@ namespace OneSignalSDK {
45
46
 
46
47
  public override NotificationPermission NotificationPermission {
47
48
  get {
48
- if (Json.Deserialize(_getDeviceState()) is Dictionary<string, object> deviceState) {
49
- if (deviceState["notificationPermissionStatus"] is long status)
50
- return (NotificationPermission) status;
51
- }
52
-
53
- SDKDebug.Error("Could not deserialize device state for permissions");
54
- return NotificationPermission.NotDetermined;
49
+ var deviceState = JsonUtility.FromJson<DeviceState>(_getDeviceState());
50
+ return (NotificationPermission)deviceState.notificationPermissionStatus;
55
51
  }
56
52
  }
57
53
 
58
- public override PushSubscriptionState PushSubscriptionState {
59
- get {
60
- if (Json.Deserialize(_getDeviceState()) is Dictionary<string, object> deviceState) {
61
- return new PushSubscriptionState {
62
- userId = deviceState["userId"] as string,
63
- pushToken = deviceState["pushToken"] as string,
64
- isSubscribed = (bool) deviceState["isSubscribed"],
65
- isPushDisabled = (bool) deviceState["isPushDisabled"],
66
- };
67
- }
68
-
69
- SDKDebug.Error("Could not deserialize device state for push");
70
- return null;
71
- }
72
- }
54
+ public override PushSubscriptionState PushSubscriptionState
55
+ => JsonUtility.FromJson<DeviceState>(_getDeviceState());
73
56
 
74
- public override EmailSubscriptionState EmailSubscriptionState {
75
- get {
76
- if (Json.Deserialize(_getDeviceState()) is Dictionary<string, object> deviceState) {
77
- return new EmailSubscriptionState {
78
- emailUserId = deviceState["emailUserId"] as string,
79
- emailAddress = deviceState["emailAddress"] as string,
80
- isSubscribed = (bool) deviceState["isEmailSubscribed"],
81
- };
82
- }
83
-
84
- SDKDebug.Error("Could not deserialize device state for email");
85
- return null;
86
- }
87
- }
57
+ public override EmailSubscriptionState EmailSubscriptionState
58
+ => JsonUtility.FromJson<DeviceState>(_getDeviceState());
88
59
 
89
- public override SMSSubscriptionState SMSSubscriptionState {
90
- get {
91
- if (Json.Deserialize(_getDeviceState()) is Dictionary<string, object> deviceState) {
92
- return new SMSSubscriptionState {
93
- smsUserId = deviceState["smsUserId"] as string,
94
- smsNumber = deviceState["smsNumber"] as string,
95
- isSubscribed = (bool) deviceState["isSMSSubscribed"],
96
- };
97
- }
98
-
99
- SDKDebug.Error("Could not deserialize device state for sms");
100
- return null;
101
- }
102
- }
60
+ public override SMSSubscriptionState SMSSubscriptionState
61
+ => JsonUtility.FromJson<DeviceState>(_getDeviceState());
103
62
 
104
63
  public override LogLevel LogLevel {
105
64
  get => _logLevel;
@@ -127,6 +86,9 @@ namespace OneSignalSDK {
127
86
  set => _setRequiresPrivacyConsent(value);
128
87
  }
129
88
 
89
+ public override void SetLaunchURLsInApp(bool launchInApp)
90
+ => _setLaunchURLsInApp(launchInApp);
91
+
130
92
  public override void Initialize(string appId) {
131
93
  _initialize(appId);
132
94
  _completedInit(appId);
@@ -141,6 +103,14 @@ namespace OneSignalSDK {
141
103
  public override void ClearOneSignalNotifications()
142
104
  => SDKDebug.Info("ClearOneSignalNotifications invoked on iOS, does nothing");
143
105
 
106
+ public override bool PushEnabled {
107
+ get {
108
+ var deviceState = JsonUtility.FromJson<DeviceState>(_getDeviceState());
109
+ return !deviceState.isPushDisabled;
110
+ }
111
+ set => _disablePush(!value);
112
+ }
113
+
144
114
  public override async Task<Dictionary<string, object>> PostNotification(Dictionary<string, object> options) {
145
115
  var (proxy, hashCode) = _setupProxy<string>();
146
116
  _postNotification(Json.Serialize(options), hashCode, StringCallbackProxy);
@@ -222,6 +192,12 @@ namespace OneSignalSDK {
222
192
  return await proxy;
223
193
  }
224
194
 
195
+ public override async Task<bool> RemoveExternalUserId() {
196
+ var (proxy, hashCode) = _setupProxy<bool>();
197
+ _removeExternalUserId(hashCode, BooleanCallbackProxy);
198
+ return await proxy;
199
+ }
200
+
225
201
  public override async Task<bool> LogOutEmail() {
226
202
  var (proxy, hashCode) = _setupProxy<bool>();
227
203
  _logoutEmail(hashCode, BooleanCallbackProxy);
@@ -25,7 +25,7 @@
25
25
  <key>NSExtensionPointIdentifier</key>
26
26
  <string>com.apple.usernotifications.service</string>
27
27
  <key>NSExtensionPrincipalClass</key>
28
- <string>NotificationService</string>
28
+ <string>$(PRODUCT_MODULE_NAME).NotificationService</string>
29
29
  </dict>
30
30
  </dict>
31
31
  </plist>
@@ -216,15 +216,15 @@ void _setEmailSubscriptionStateChangedCallback(StateListenerDelegate callback) {
216
216
  [[OneSignalObserver sharedObserver] setEmailDelegate:callback];
217
217
  }
218
218
 
219
- void _setSMSSubscriptionStateChangedCallback(StateListenerDelegate callback) {
220
- [[OneSignalObserver sharedObserver] setSmsDelegate:callback];
221
- }
222
-
223
- const char* _getDeviceState() {
224
- auto deviceState = [OneSignal getDeviceState];
225
- auto stateStr = jsonStringFromDictionary([deviceState jsonRepresentation]);
226
- return strdup(stateStr);
227
- }
219
+ void _setSMSSubscriptionStateChangedCallback(StateListenerDelegate callback) {
220
+ [[OneSignalObserver sharedObserver] setSmsDelegate:callback];
221
+ }
222
+
223
+ const char* _getDeviceState() {
224
+ auto deviceState = [OneSignal getDeviceState];
225
+ auto stateStr = jsonStringFromDictionary([deviceState jsonRepresentation]);
226
+ return strdup(stateStr);
227
+ }
228
228
 
229
229
  void _setLogLevel(int logLevel, int alertLevel) {
230
230
  [OneSignal setLogLevel:(ONE_S_LOG_LEVEL) logLevel
@@ -247,6 +247,10 @@ bool _getRequiresPrivacyConsent() {
247
247
  return [OneSignal requiresUserPrivacyConsent];
248
248
  }
249
249
 
250
+ void _setLaunchURLsInApp(bool launchInApp) {
251
+ [OneSignal setLaunchURLsInApp: launchInApp];
252
+ }
253
+
250
254
  void _initialize(const char* appId) {
251
255
  [OneSignal setAppId:TO_NSSTRING(appId)];
252
256
  [OneSignal initWithLaunchOptions:nil];
@@ -258,6 +262,10 @@ void _promptForPushNotificationsWithUserResponse(int hashCode, BooleanResponseDe
258
262
  }];
259
263
  }
260
264
 
265
+ void _disablePush(bool disable) {
266
+ [OneSignal disablePush:disable];
267
+ }
268
+
261
269
  void _postNotification(const char* optionsJson, int hashCode, StringResponseDelegate callback) {
262
270
  NSDictionary *options = objFromJsonString<NSDictionary*>(optionsJson);
263
271
 
@@ -369,6 +377,11 @@ void _setSMSNumber(const char* smsNumber, const char* authHash, int hashCode, Bo
369
377
  withFailure:^(NSError *error) { CALLBACK(NO); }];
370
378
  }
371
379
 
380
+ void _removeExternalUserId(int hashCode, BooleanResponseDelegate callback) {
381
+ [OneSignal removeExternalUserId:^(NSDictionary *results) { CALLBACK(YES); }
382
+ withFailure:^(NSError *error) { CALLBACK(NO); }];
383
+ }
384
+
372
385
  void _logoutEmail(int hashCode, BooleanResponseDelegate callback) {
373
386
  [OneSignal logoutEmailWithSuccess:^{ CALLBACK(YES); }
374
387
  withFailure:^(NSError *error) { CALLBACK(NO); }];
@@ -376,18 +389,18 @@ void _logoutEmail(int hashCode, BooleanResponseDelegate callback) {
376
389
 
377
390
  void _logoutSMSNumber(int hashCode, BooleanResponseDelegate callback) {
378
391
  [OneSignal logoutSMSNumberWithSuccess:^(NSDictionary *results) { CALLBACK(YES); }
379
- withFailure:^(NSError *error) { CALLBACK(NO); }];
380
- }
392
+ withFailure:^(NSError *error) { CALLBACK(NO); }];
393
+ }
381
394
 
382
- void _setLanguage(const char* languageCode, int hashCode, BooleanResponseDelegate callback) {
383
- [OneSignal setLanguage:TO_NSSTRING(languageCode)
384
- withSuccess:^{ CALLBACK(YES); }
385
- withFailure:^(NSError *error) { CALLBACK(NO); }];
386
- }
395
+ void _setLanguage(const char* languageCode, int hashCode, BooleanResponseDelegate callback) {
396
+ [OneSignal setLanguage:TO_NSSTRING(languageCode)
397
+ withSuccess:^{ CALLBACK(YES); }
398
+ withFailure:^(NSError *error) { CALLBACK(NO); }];
399
+ }
387
400
 
388
- void _promptLocation() {
389
- [OneSignal promptLocation];
390
- }
401
+ void _promptLocation() {
402
+ [OneSignal promptLocation];
403
+ }
391
404
 
392
405
  void _setShareLocation(bool share) {
393
406
  [OneSignal setLocationShared:share];
@@ -0,0 +1,32 @@
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 <UIKit/UIKit.h>
29
+
30
+ @interface UIApplication (OneSignalUnity)
31
+ @end
32
+
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: a4a2cda353724bccbd11343516cb4c27
3
+ timeCreated: 1649879476
@@ -0,0 +1,105 @@
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 "UIApplication+OneSignalUnity.h"
29
+ #import <OneSignal/OneSignal.h>
30
+ #import <objc/runtime.h>
31
+
32
+ // from OneSignalSelectorHelpers.m
33
+ static Class getClassWithProtocolInHierarchy(Class searchClass, Protocol *protocolToFind) {
34
+ if (!class_conformsToProtocol(searchClass, protocolToFind)) {
35
+ if ([searchClass superclass] == [NSObject class])
36
+ return nil;
37
+ Class foundClass = getClassWithProtocolInHierarchy([searchClass superclass], protocolToFind);
38
+ if (foundClass)
39
+ return foundClass;
40
+ return searchClass;
41
+ }
42
+ return searchClass;
43
+ }
44
+
45
+ // from OneSignalSelectorHelpers.m
46
+ BOOL injectSelector(Class newClass, SEL newSel, Class addToClass, SEL makeLikeSel) {
47
+ Method newMeth = class_getInstanceMethod(newClass, newSel);
48
+ IMP imp = method_getImplementation(newMeth);
49
+
50
+ const char* methodTypeEncoding = method_getTypeEncoding(newMeth);
51
+ BOOL existing = class_getInstanceMethod(addToClass, makeLikeSel) != NULL;
52
+
53
+ if (existing) {
54
+ class_addMethod(addToClass, newSel, imp, methodTypeEncoding);
55
+ newMeth = class_getInstanceMethod(addToClass, newSel);
56
+ Method orgMeth = class_getInstanceMethod(addToClass, makeLikeSel);
57
+ method_exchangeImplementations(orgMeth, newMeth);
58
+ }
59
+ else {
60
+ class_addMethod(addToClass, makeLikeSel, imp, methodTypeEncoding);
61
+ }
62
+
63
+ return existing;
64
+ }
65
+
66
+ static bool swizzled = false;
67
+
68
+ @implementation UIApplication (OneSignalUnity)
69
+
70
+ + (void)load {
71
+ method_exchangeImplementations(
72
+ class_getInstanceMethod(self, @selector(setDelegate:)),
73
+ class_getInstanceMethod(self, @selector(setOneSignalUnityDelegate:))
74
+ );
75
+ }
76
+
77
+ - (void)setOneSignalUnityDelegate:(id <UIApplicationDelegate>)delegate {
78
+ if (swizzled) {
79
+ [self setOneSignalUnityDelegate:delegate];
80
+ return;
81
+ }
82
+
83
+ Class delegateClass = getClassWithProtocolInHierarchy([delegate class], @protocol(UIApplicationDelegate));
84
+
85
+ injectSelector(
86
+ self.class, @selector(oneSignalApplication:didFinishLaunchingWithOptions:),
87
+ delegateClass, @selector(application:didFinishLaunchingWithOptions:)
88
+ );
89
+
90
+ swizzled = true;
91
+
92
+ [self setOneSignalUnityDelegate:delegate];
93
+ }
94
+
95
+ - (BOOL)oneSignalApplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
96
+ [OneSignal setMSDKType:@"unity"];
97
+ [OneSignal initWithLaunchOptions:launchOptions];
98
+
99
+ if ([self respondsToSelector:@selector(oneSignalApplication:didFinishLaunchingWithOptions:)])
100
+ return [self oneSignalApplication:application didFinishLaunchingWithOptions:launchOptions];
101
+
102
+ return YES;
103
+ }
104
+
105
+ @end
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: a8e9b06e260e4c0ca80d5e51137d89d3
3
+ timeCreated: 1649879476
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": "3.0.0-beta.5",
4
+ "version": "3.0.1",
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": "3.0.0-beta.5"
8
+ "com.onesignal.unity.core": "3.0.1"
9
9
  },
10
10
  "keywords": [
11
11
  "push-notifications",