com.onesignal.unity.ios 2.14.6 → 3.0.0-beta.4

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 +297 -0
  2. package/Editor/{PostProcessBuildPlayer_iOS.cs.meta → BuildPostProcessor.cs.meta} +0 -0
  3. package/Editor/OneSignalIOSDependencies.xml +5 -0
  4. package/Editor/OneSignalIOSDependencies.xml.meta +3 -0
  5. package/Editor/PBXProjectExtensions.cs +52 -0
  6. package/Editor/PBXProjectExtensions.cs.meta +3 -0
  7. package/Runtime/AssemblyInfo.cs +28 -1
  8. package/Runtime/OneSignal.iOS.asmdef +4 -3
  9. package/Runtime/OneSignalIOS.Callbacks.cs +174 -0
  10. package/Runtime/OneSignalIOS.Callbacks.cs.meta +3 -0
  11. package/Runtime/OneSignalIOS.Interface.cs +99 -0
  12. package/Runtime/OneSignalIOS.Interface.cs.meta +3 -0
  13. package/Runtime/OneSignalIOS.cs +268 -457
  14. package/Runtime/OneSignalIOS.cs.meta +3 -10
  15. package/Runtime/OneSignalIOSInit.cs +39 -9
  16. package/Runtime/Plugins/iOS/Info.plist.meta +1 -3
  17. package/Runtime/Plugins/iOS/NotificationService.swift +25 -0
  18. package/Runtime/Plugins/iOS/{NotificationService.m.meta → NotificationService.swift.meta} +5 -4
  19. package/Runtime/Plugins/iOS/OneSignalUnityBridge.mm +417 -0
  20. package/Runtime/Plugins/iOS/{OneSignal.h.meta → OneSignalUnityBridge.mm.meta} +16 -5
  21. package/Runtime/Utilities/Later.cs +64 -0
  22. package/Runtime/Utilities/Later.cs.meta +11 -0
  23. package/Runtime/Utilities.meta +3 -0
  24. package/package.json +2 -2
  25. package/Editor/PostProcessBuildPlayer_iOS.cs +0 -399
  26. package/Runtime/Plugins/iOS/NotificationService.h +0 -13
  27. package/Runtime/Plugins/iOS/NotificationService.h.meta +0 -26
  28. package/Runtime/Plugins/iOS/NotificationService.m +0 -40
  29. package/Runtime/Plugins/iOS/OneSignal.h +0 -617
  30. package/Runtime/Plugins/iOS/OneSignalUnityRuntime.m +0 -542
  31. package/Runtime/Plugins/iOS/OneSignalUnityRuntime.m.meta +0 -24
  32. package/Runtime/Plugins/iOS/libOneSignal.a +0 -0
  33. package/Runtime/Plugins/iOS/libOneSignal.a.meta +0 -21
@@ -0,0 +1,297 @@
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
+ /*
29
+ * Testing Notes
30
+ * When making any changes please test the following senerios
31
+ * 1. Building to a new directory
32
+ * 2. Appending. Running a 2nd time
33
+ * 2. Appending. Coming from the last released version
34
+ * 3. Appending. Coming from a project without OneSignal
35
+ *
36
+ * In each of the tests ensure the NSE + App Groups work by doing the following:
37
+ * 1. Send a notification with Badge set to Increase by 1
38
+ * 2. Send a 2nd identical notification
39
+ * 3. Observe Badge value on device as 2. (NSE is working)
40
+ * 4. Open app and then background it again, Badge value will be cleared.
41
+ * 5. Send a 3rd identical notification.
42
+ * 6. Observe Badge value is 1. (If it is 3 there is an App Group issue)
43
+ */
44
+
45
+ // Flag if an App Group should created for the main target and the NSE
46
+ // Try renaming NOTIFICATION_SERVICE_EXTENSION_TARGET_NAME below first before
47
+ // removing ADD_APP_GROUP if you run into Provisioning errors in Xcode that
48
+ // can't be fix.
49
+ // ADD_APP_GROUP is required for;
50
+ // Outcomes, Badge Increment, and possibly for future features
51
+
52
+ #define ADD_APP_GROUP
53
+
54
+ using System.IO;
55
+ using System;
56
+ using UnityEditor;
57
+ using UnityEditor.iOS.Xcode;
58
+ using System.Collections.Generic;
59
+ using System.Diagnostics;
60
+ using System.Linq;
61
+ using System.Text.RegularExpressions;
62
+ using UnityEditor.Build;
63
+ using UnityEditor.Build.Reporting;
64
+ using UnityEditor.iOS.Xcode.Extensions;
65
+ using Debug = UnityEngine.Debug;
66
+
67
+ namespace OneSignalSDK {
68
+ /// <summary>
69
+ /// Adds required frameworks to the iOS project, and adds the OneSignalNotificationServiceExtension. Also handles
70
+ /// making sure both targets (app and extension service) have the correct dependencies
71
+ /// </summary>
72
+ public class BuildPostProcessor : IPostprocessBuildWithReport {
73
+ private const string ServiceExtensionTargetName = "OneSignalNotificationServiceExtension";
74
+ private const string ServiceExtensionFilename = "NotificationService.swift";
75
+ private const string PackageName = "com.onesignal.unity.ios";
76
+
77
+ private static readonly string PluginLibrariesPath = Path.Combine(PackageName, "Runtime", "Plugins", "iOS");
78
+ private static readonly string PluginFilesPath = Path.Combine("Packages", PluginLibrariesPath);
79
+
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
+
91
+ private string _outputPath;
92
+ private string _projectPath;
93
+
94
+ private readonly PBXProject _project = new PBXProject();
95
+
96
+ /// <summary>
97
+ /// must be between 40 and 50 to ensure that it's not overriden by Podfile generation (40) and that it's
98
+ /// added before "pod install" (50)
99
+ /// https://github.com/googlesamples/unity-jar-resolver#appending-text-to-generated-podfile
100
+ /// </summary>
101
+ public int callbackOrder => 45;
102
+
103
+ /// <summary>
104
+ /// Entry for the build post processing necessary to get the OneSignal SDK iOS up and running
105
+ /// </summary>
106
+ public void OnPostprocessBuild(BuildReport report) {
107
+ if (report.summary.platform != BuildTarget.iOS)
108
+ return;
109
+
110
+ // Load the project
111
+ _outputPath = report.summary.outputPath;
112
+ _projectPath = PBXProject.GetPBXProjectPath(_outputPath);
113
+ _project.ReadFromString(File.ReadAllText(_projectPath));
114
+
115
+ // Add required entitlements
116
+ UpdateEntitlements(Entitlement.ApsEnv | Entitlement.AppGroups);
117
+
118
+ // Add the service extension
119
+ AddNotificationServiceExtension();
120
+
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
+ // Save the project back out
132
+ File.WriteAllText(_projectPath, _project.WriteToString());
133
+ }
134
+
135
+ /// <summary>
136
+ /// Checks for existing entitlements file or creates a new one and returns the path
137
+ /// </summary>
138
+ private string GetEntitlementsPath(string targetGuid, string targetName) {
139
+ var relativePath = _project.GetBuildPropertyForAnyConfig(targetGuid, "CODE_SIGN_ENTITLEMENTS");
140
+
141
+ if (relativePath != null) {
142
+ var fullPath = Path.Combine(_outputPath, relativePath);
143
+
144
+ if (File.Exists(fullPath))
145
+ return fullPath;
146
+ }
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);
156
+ 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
+ entitlementsPlist.WriteToFile(entitlementsPath);
176
+
177
+ if (existingEntitlements)
178
+ return;
179
+
180
+ // Copy the entitlement file to the xcode project
181
+ var entitlementFileName = Path.GetFileName(entitlementsPath);
182
+ var relativeDestination = targetName + "/" + entitlementFileName;
183
+
184
+ // Add the pbx configs to include the entitlements files on the project
185
+ _project.AddFile(relativeDestination, entitlementFileName);
186
+ _project.SetBuildProperty(targetGuid, "CODE_SIGN_ENTITLEMENTS", relativeDestination);
187
+ }
188
+
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);
195
+
196
+ var entitlementsPath = GetEntitlementsPath(targetGuid, targetName);
197
+
198
+ // NOTE: ProjectCapabilityManager's 4th constructor param requires Unity 2019.3+
199
+ var projCapability = new ProjectCapabilityManager(_projectPath, entitlementsPath, targetName);
200
+ projCapability.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications);
201
+ projCapability.WriteToFile();
202
+ }
203
+
204
+ private void AddPushCapability() =>
205
+ AddPushCapability(_project.GetMainTargetGuid(), _project.GetMainTargetName());
206
+
207
+ /// <summary>
208
+ /// Create and add the notification extension to the project
209
+ /// </summary>
210
+ private void AddNotificationServiceExtension() {
211
+ #if !UNITY_CLOUD_BUILD
212
+ // If file exists then the below has been completed before from another build
213
+ // The below will not be updated on Append builds
214
+ // Changes would most likely need to be made to support Append builds
215
+ if (ExtensionCreatePlist(_outputPath))
216
+ return;
217
+
218
+ var extensionGuid = _project.AddAppExtension(_project.GetMainTargetGuid(),
219
+ ServiceExtensionTargetName,
220
+ PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS) + "." + ServiceExtensionTargetName,
221
+ ServiceExtensionTargetName + "/" + "Info.plist" // Unix path as it's used by Xcode
222
+ );
223
+
224
+ ExtensionAddSourceFiles(extensionGuid);
225
+
226
+ // Makes it so that the extension target is Universal (not just iPhone) and has an iOS 10 deployment target
227
+ _project.SetBuildProperty(extensionGuid, "TARGETED_DEVICE_FAMILY", "1,2");
228
+ _project.SetBuildProperty(extensionGuid, "IPHONEOS_DEPLOYMENT_TARGET", "10.0");
229
+ _project.SetBuildProperty(extensionGuid, "SWIFT_VERSION", "5.0");
230
+ _project.SetBuildProperty(extensionGuid, "ARCHS", "arm64");
231
+ _project.SetBuildProperty(extensionGuid, "DEVELOPMENT_TEAM", PlayerSettings.iOS.appleDeveloperTeamID);
232
+
233
+ _project.AddBuildProperty(extensionGuid, "LIBRARY_SEARCH_PATHS",
234
+ $"$(PROJECT_DIR)/Libraries/{PluginLibrariesPath.Replace("\\", "/")}");
235
+
236
+ _project.WriteToFile(_projectPath);
237
+
238
+ UpdateEntitlements(Entitlement.AppGroups, extensionGuid, ServiceExtensionTargetName);
239
+ #endif
240
+ }
241
+
242
+ /// <summary>
243
+ /// Add the swift source file required by the notification extension
244
+ /// </summary>
245
+ private void ExtensionAddSourceFiles(string extensionGuid) {
246
+ var buildPhaseID = _project.AddSourcesBuildPhase(extensionGuid);
247
+ var sourcePath = Path.Combine(PluginFilesPath, ServiceExtensionFilename);
248
+ var destPathRelative = Path.Combine(ServiceExtensionTargetName, ServiceExtensionFilename);
249
+
250
+ var destPath = Path.Combine(_outputPath, destPathRelative);
251
+ if (!File.Exists(destPath))
252
+ FileUtil.CopyFileOrDirectory(sourcePath.Replace("\\", "/"), destPath.Replace("\\", "/"));
253
+
254
+ var sourceFileGuid = _project.AddFile(destPathRelative, destPathRelative);
255
+ _project.AddFileToBuildSection(extensionGuid, buildPhaseID, sourceFileGuid);
256
+ }
257
+
258
+ /// <summary>
259
+ /// Create a .plist file for the extension
260
+ /// </summary>
261
+ /// <remarks>NOTE: File in Xcode project is replaced everytime, never appends</remarks>
262
+ private bool ExtensionCreatePlist(string path) {
263
+ var extensionPath = Path.Combine(path, ServiceExtensionTargetName);
264
+ Directory.CreateDirectory(extensionPath);
265
+
266
+ var plistPath = Path.Combine(extensionPath, "Info.plist");
267
+ var alreadyExists = File.Exists(plistPath);
268
+
269
+ var notificationServicePlist = new PlistDocument();
270
+ notificationServicePlist.ReadFromFile(Path.Combine(PluginFilesPath, "Info.plist"));
271
+ notificationServicePlist.root.SetString("CFBundleShortVersionString", PlayerSettings.bundleVersion);
272
+ notificationServicePlist.root.SetString("CFBundleVersion", PlayerSettings.iOS.buildNumber);
273
+
274
+ notificationServicePlist.WriteToFile(plistPath);
275
+
276
+ return alreadyExists;
277
+ }
278
+
279
+ private void ExtensionAddPodsToTarget() {
280
+ var podfilePath = Path.Combine(_outputPath, "Podfile");
281
+
282
+ if (!File.Exists(podfilePath)) {
283
+ Debug.LogError($"Could not find Podfile. {ServiceExtensionFilename} will have errors.");
284
+ return;
285
+ }
286
+
287
+ var podfile = File.ReadAllText(podfilePath);
288
+
289
+ var extensionEntryRegex = new Regex($@"target '{ServiceExtensionTargetName}' do\n(.+)\nend");
290
+ if (extensionEntryRegex.IsMatch(podfile))
291
+ return;
292
+
293
+ podfile += $"target '{ServiceExtensionTargetName}' do\n pod 'OneSignalXCFramework', '~> 3.8.1'\nend\n";
294
+ File.WriteAllText(podfilePath, podfile);
295
+ }
296
+ }
297
+ }
@@ -0,0 +1,5 @@
1
+ <dependencies>
2
+ <iosPods>
3
+ <iosPod name="OneSignalXCFramework" version="~> 3.8.1" addToAllTargets="true" />
4
+ </iosPods>
5
+ </dependencies>
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 033a0fbaaa064a48ad2e72d8e35d5f36
3
+ timeCreated: 1631806154
@@ -0,0 +1,52 @@
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 UnityEditor.iOS.Xcode;
29
+
30
+ namespace OneSignalSDK {
31
+ public static class PBXProjectExtensions {
32
+ #if UNITY_2019_3_OR_NEWER
33
+ public static string GetMainTargetName(this PBXProject project)
34
+ => "Unity-iPhone";
35
+
36
+ public static string GetMainTargetGuid(this PBXProject project)
37
+ => project.GetUnityMainTargetGuid();
38
+
39
+ public static string GetFrameworkGuid(this PBXProject project)
40
+ => project.GetUnityFrameworkTargetGuid();
41
+ #else
42
+ public static string GetMainTargetName(this PBXProject project)
43
+ => PBXProject.GetUnityTargetName();
44
+
45
+ public static string GetMainTargetGuid(this PBXProject project)
46
+ => project.TargetGuidByName(PBXProject.GetUnityTargetName());
47
+
48
+ public static string GetFrameworkGuid(this PBXProject project)
49
+ => GetPBXProjectTargetGuid(project);
50
+ #endif
51
+ }
52
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 298849f4da9b4a6baba5b6a2b41f4487
3
+ timeCreated: 1634920335
@@ -1,3 +1,30 @@
1
- using UnityEngine.Scripting;
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 UnityEngine.Scripting;
2
29
 
3
30
  [assembly: AlwaysLinkAssembly]
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "OneSignal.iOS",
3
+ "rootNamespace": "",
3
4
  "references": [
4
5
  "OneSignal.Core"
5
6
  ],
6
- "optionalUnityReferences": [],
7
7
  "includePlatforms": [
8
- "Editor",
9
8
  "iOS"
10
9
  ],
11
10
  "excludePlatforms": [],
@@ -13,5 +12,7 @@
13
12
  "overrideReferences": false,
14
13
  "precompiledReferences": [],
15
14
  "autoReferenced": false,
16
- "defineConstraints": []
15
+ "defineConstraints": [],
16
+ "versionDefines": [],
17
+ "noEngineReferences": false
17
18
  }
@@ -0,0 +1,174 @@
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.Collections.Generic;
29
+ using Laters;
30
+ using UnityEngine;
31
+
32
+ namespace OneSignalSDK {
33
+ public sealed partial class OneSignalIOS : OneSignal {
34
+ private delegate void BooleanResponseDelegate(int hashCode, bool response);
35
+ private delegate void StringResponseDelegate(int hashCode, string response);
36
+
37
+ private delegate void BooleanListenerDelegate(bool response);
38
+ private delegate void StringListenerDelegate(string response);
39
+ private delegate void StateListenerDelegate(string current, string previous);
40
+
41
+ private delegate bool NotificationWillShowInForegroundDelegate(string notification);
42
+
43
+ private static readonly Dictionary<int, ILater> WaitingProxies = new Dictionary<int, ILater>();
44
+
45
+ private static (Later<TResult> proxy, int hashCode) _setupProxy<TResult>() {
46
+ var proxy = new Later<TResult>();
47
+ var hashCode = proxy.GetHashCode();
48
+ WaitingProxies[hashCode] = proxy;
49
+ return (proxy, hashCode);
50
+ }
51
+
52
+ [AOT.MonoPInvokeCallback(typeof(BooleanResponseDelegate))]
53
+ private static void BooleanCallbackProxy(int hashCode, bool response) {
54
+ if (WaitingProxies[hashCode] is Later<bool> later)
55
+ later.Complete(response);
56
+ WaitingProxies.Remove(hashCode);
57
+ }
58
+
59
+ [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
+ }
65
+
66
+ /*
67
+ * Global Callbacks
68
+ */
69
+
70
+ private static OneSignalIOS _instance;
71
+
72
+ /// <summary>
73
+ /// Used to provide a reference for and sets up the global callbacks
74
+ /// </summary>
75
+ public OneSignalIOS() {
76
+ if (_instance != null)
77
+ SDKDebug.Error("Additional instance of OneSignalIOS created.");
78
+
79
+ _setNotificationReceivedCallback(_onNotificationReceived);
80
+ _setNotificationOpenedCallback(_onNotificationOpened);
81
+
82
+ _setInAppMessageWillDisplayCallback(_onInAppMessageWillDisplay);
83
+ _setInAppMessageDidDisplayCallback(_onInAppMessageDidDisplay);
84
+ _setInAppMessageWillDismissCallback(_onInAppMessageWillDismiss);
85
+ _setInAppMessageDidDismissCallback(_onInAppMessageDidDismiss);
86
+ _setInAppMessageClickedCallback(_onInAppMessageClicked);
87
+
88
+ _setPermissionStateChangedCallback(_onPermissionStateChanged);
89
+ _setSubscriptionStateChangedCallback(_onSubscriptionStateChanged);
90
+ _setEmailSubscriptionStateChangedCallback(_onEmailSubscriptionStateChanged);
91
+ _setSMSSubscriptionStateChangedCallback(_onSMSSubscriptionStateChanged);
92
+
93
+ _instance = this;
94
+ }
95
+
96
+ [AOT.MonoPInvokeCallback(typeof(NotificationWillShowInForegroundDelegate))]
97
+ private static bool _onNotificationReceived(string response) {
98
+ if (_instance.NotificationWillShow == null)
99
+ return true;
100
+
101
+ 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>;
105
+
106
+ var resultNotif = _instance.NotificationWillShow(notification);
107
+
108
+ return resultNotif != null;
109
+ }
110
+
111
+ [AOT.MonoPInvokeCallback(typeof(StringListenerDelegate))]
112
+ private static void _onNotificationOpened(string response)
113
+ => _instance.NotificationOpened?.Invoke(JsonUtility.FromJson<NotificationOpenedResult>(response));
114
+
115
+ [AOT.MonoPInvokeCallback(typeof(StringListenerDelegate))]
116
+ private static void _onInAppMessageWillDisplay(string response)
117
+ => _instance.InAppMessageWillDisplay?.Invoke(new InAppMessage { messageId = response });
118
+
119
+ [AOT.MonoPInvokeCallback(typeof(StringListenerDelegate))]
120
+ private static void _onInAppMessageDidDisplay(string response)
121
+ => _instance.InAppMessageDidDisplay?.Invoke(new InAppMessage { messageId = response });
122
+
123
+ [AOT.MonoPInvokeCallback(typeof(StringListenerDelegate))]
124
+ private static void _onInAppMessageWillDismiss(string response)
125
+ => _instance.InAppMessageWillDismiss?.Invoke(new InAppMessage { messageId = response });
126
+
127
+ [AOT.MonoPInvokeCallback(typeof(StringListenerDelegate))]
128
+ private static void _onInAppMessageDidDismiss(string response)
129
+ => _instance.InAppMessageDidDismiss?.Invoke(new InAppMessage { messageId = response });
130
+
131
+ [AOT.MonoPInvokeCallback(typeof(StringListenerDelegate))]
132
+ private static void _onInAppMessageClicked(string response)
133
+ => _instance.InAppMessageTriggeredAction?.Invoke(JsonUtility.FromJson<InAppMessageAction>(response));
134
+
135
+ [AOT.MonoPInvokeCallback(typeof(StateListenerDelegate))]
136
+ 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
+
150
+ _instance.NotificationPermissionChanged?.Invoke(curr, prev);
151
+ }
152
+
153
+ [AOT.MonoPInvokeCallback(typeof(StateListenerDelegate))]
154
+ private static void _onSubscriptionStateChanged(string current, string previous) {
155
+ var curr = JsonUtility.FromJson<PushSubscriptionState>(current);
156
+ var prev = JsonUtility.FromJson<PushSubscriptionState>(previous);
157
+ _instance.PushSubscriptionStateChanged?.Invoke(curr, prev);
158
+ }
159
+
160
+ [AOT.MonoPInvokeCallback(typeof(StateListenerDelegate))]
161
+ private static void _onEmailSubscriptionStateChanged(string current, string previous) {
162
+ var curr = JsonUtility.FromJson<EmailSubscriptionState>(current);
163
+ var prev = JsonUtility.FromJson<EmailSubscriptionState>(previous);
164
+ _instance.EmailSubscriptionStateChanged?.Invoke(curr, prev);
165
+ }
166
+
167
+ [AOT.MonoPInvokeCallback(typeof(StateListenerDelegate))]
168
+ private static void _onSMSSubscriptionStateChanged(string current, string previous) {
169
+ var curr = JsonUtility.FromJson<SMSSubscriptionState>(current);
170
+ var prev = JsonUtility.FromJson<SMSSubscriptionState>(previous);
171
+ _instance.SMSSubscriptionStateChanged?.Invoke(curr, prev);
172
+ }
173
+ }
174
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 15a2f9cb8eec46f6b7a2b509375eea1d
3
+ timeCreated: 1631805103