com.onesignal.unity.ios 2.14.5 → 3.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.
Files changed (32) hide show
  1. package/Editor/BuildPostProcessor.cs +289 -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/OneSignal.iOS.asmdef +4 -3
  8. package/Runtime/OneSignalIOS.Callbacks.cs +174 -0
  9. package/Runtime/OneSignalIOS.Callbacks.cs.meta +3 -0
  10. package/Runtime/OneSignalIOS.Interface.cs +99 -0
  11. package/Runtime/OneSignalIOS.Interface.cs.meta +3 -0
  12. package/Runtime/OneSignalIOS.cs +266 -457
  13. package/Runtime/OneSignalIOS.cs.meta +3 -10
  14. package/Runtime/OneSignalIOSInit.cs +36 -9
  15. package/Runtime/Plugins/iOS/Info.plist.meta +1 -3
  16. package/Runtime/Plugins/iOS/NotificationService.swift +25 -0
  17. package/Runtime/Plugins/iOS/{NotificationService.m.meta → NotificationService.swift.meta} +5 -4
  18. package/Runtime/Plugins/iOS/OneSignalUnityBridge.mm +417 -0
  19. package/Runtime/Plugins/iOS/{OneSignal.h.meta → OneSignalUnityBridge.mm.meta} +16 -5
  20. package/Runtime/Utilities/Later.cs +64 -0
  21. package/Runtime/Utilities/Later.cs.meta +11 -0
  22. package/Runtime/Utilities.meta +3 -0
  23. package/package.json +2 -2
  24. package/Editor/PostProcessBuildPlayer_iOS.cs +0 -399
  25. package/Runtime/Plugins/iOS/NotificationService.h +0 -13
  26. package/Runtime/Plugins/iOS/NotificationService.h.meta +0 -26
  27. package/Runtime/Plugins/iOS/NotificationService.m +0 -40
  28. package/Runtime/Plugins/iOS/OneSignal.h +0 -617
  29. package/Runtime/Plugins/iOS/OneSignalUnityRuntime.m +0 -542
  30. package/Runtime/Plugins/iOS/OneSignalUnityRuntime.m.meta +0 -24
  31. package/Runtime/Plugins/iOS/libOneSignal.a +0 -0
  32. package/Runtime/Plugins/iOS/libOneSignal.a.meta +0 -21
@@ -0,0 +1,289 @@
1
+ /*
2
+ * Modified MIT License
3
+ *
4
+ * Copyright 2021 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
+ * Testing Notes
29
+ * When making any changes please test the following senerios
30
+ * 1. Building to a new directory
31
+ * 2. Appending. Running a 2nd time
32
+ * 2. Appending. Coming from the last released version
33
+ * 3. Appending. Coming from a project without OneSignal
34
+ *
35
+ * In each of the tests ensure the NSE + App Groups work by doing the following:
36
+ * 1. Send a notification with Badge set to Increase by 1
37
+ * 2. Send a 2nd identical notification
38
+ * 3. Observe Badge value on device as 2. (NSE is working)
39
+ * 4. Open app and then background it again, Badge value will be cleared.
40
+ * 5. Send a 3rd identical notification.
41
+ * 6. Observe Badge value is 1. (If it is 3 there is an App Group issue)
42
+ */
43
+
44
+ // Flag if an App Group should created for the main target and the NSE
45
+ // Try renaming NOTIFICATION_SERVICE_EXTENSION_TARGET_NAME below first before
46
+ // removing ADD_APP_GROUP if you run into Provisioning errors in Xcode that
47
+ // can't be fix.
48
+ // ADD_APP_GROUP is required for;
49
+ // Outcomes, Badge Increment, and possibly for future features
50
+ #define ADD_APP_GROUP
51
+
52
+ using System.IO;
53
+ using System;
54
+ using UnityEditor;
55
+ using UnityEditor.iOS.Xcode;
56
+ using System.Collections.Generic;
57
+ using System.Diagnostics;
58
+ using System.Linq;
59
+ using System.Text.RegularExpressions;
60
+ using UnityEditor.Build;
61
+ using UnityEditor.Build.Reporting;
62
+ using UnityEditor.iOS.Xcode.Extensions;
63
+ using Debug = UnityEngine.Debug;
64
+
65
+ namespace OneSignalSDK {
66
+ /// <summary>
67
+ /// Adds required frameworks to the iOS project, and adds the OneSignalNotificationServiceExtension. Also handles
68
+ /// making sure both targets (app and extension service) have the correct dependencies
69
+ /// </summary>
70
+ public class BuildPostProcessor : IPostprocessBuildWithReport {
71
+ private const string ServiceExtensionTargetName = "OneSignalNotificationServiceExtension";
72
+ private const string ServiceExtensionFilename = "NotificationService.swift";
73
+ private const string PackageName = "com.onesignal.unity.ios";
74
+
75
+ private static readonly string PluginLibrariesPath = Path.Combine(PackageName, "Runtime", "Plugins", "iOS");
76
+ private static readonly string PluginFilesPath = Path.Combine("Packages", PluginLibrariesPath);
77
+
78
+ [Flags] private enum Entitlement {
79
+ None = 0,
80
+ ApsEnv = 1 << 0,
81
+ AppGroups = 1 << 1
82
+ }
83
+
84
+ private static readonly Dictionary<Entitlement, string> EntitlementKeys = new Dictionary<Entitlement, string> {
85
+ [Entitlement.ApsEnv] = "aps-environment",
86
+ [Entitlement.AppGroups] = "com.apple.security.application-groups"
87
+ };
88
+
89
+ private string _outputPath;
90
+ private string _projectPath;
91
+
92
+ private readonly PBXProject _project = new PBXProject();
93
+
94
+ /// <summary>
95
+ /// must be between 40 and 50 to ensure that it's not overriden by Podfile generation (40) and that it's
96
+ /// added before "pod install" (50)
97
+ /// https://github.com/googlesamples/unity-jar-resolver#appending-text-to-generated-podfile
98
+ /// </summary>
99
+ public int callbackOrder => 45;
100
+
101
+ /// <summary>
102
+ /// Entry for the build post processing necessary to get the OneSignal SDK iOS up and running
103
+ /// </summary>
104
+ public void OnPostprocessBuild(BuildReport report) {
105
+ if (report.summary.platform != BuildTarget.iOS)
106
+ return;
107
+
108
+ // Load the project
109
+ _outputPath = report.summary.outputPath;
110
+ _projectPath = PBXProject.GetPBXProjectPath(_outputPath);
111
+ _project.ReadFromString(File.ReadAllText(_projectPath));
112
+
113
+ // Add required entitlements
114
+ UpdateEntitlements(Entitlement.ApsEnv | Entitlement.AppGroups);
115
+
116
+ // Add the service extension
117
+ AddNotificationServiceExtension();
118
+
119
+ // Reload file after changes from AddNotificationServiceExtension
120
+ _project.WriteToFile(_projectPath);
121
+ _project.ReadFromString(File.ReadAllText(_projectPath));
122
+
123
+ // Turn on push capabilities
124
+ AddPushCapability();
125
+
126
+ // Ensure the Pods target has been added to the extension
127
+ ExtensionAddPodsToTarget();
128
+
129
+ // Save the project back out
130
+ File.WriteAllText(_projectPath, _project.WriteToString());
131
+ }
132
+
133
+ /// <summary>
134
+ /// Checks for existing entitlements file or creates a new one and returns the path
135
+ /// </summary>
136
+ private string GetEntitlementsPath(string targetGuid, string targetName) {
137
+ var relativePath = _project.GetBuildPropertyForConfig(targetGuid, "CODE_SIGN_ENTITLEMENTS");
138
+ if (relativePath != null) {
139
+ var fullPath = Path.Combine(_projectPath, relativePath);
140
+ if (File.Exists(fullPath))
141
+ return fullPath;
142
+ }
143
+
144
+ return Path.Combine(_outputPath, targetName, $"{targetName}.entitlements");
145
+ }
146
+
147
+ /// <summary>
148
+ /// Add or update the values of necessary entitlements
149
+ /// </summary>
150
+ private void UpdateEntitlements(Entitlement entitlements, string targetGuid, string targetName) {
151
+ var entitlementsPath = GetEntitlementsPath(targetGuid, targetName);
152
+ var entitlementsPlist = new PlistDocument();
153
+
154
+ if (File.Exists(entitlementsPath))
155
+ entitlementsPlist.ReadFromFile(entitlementsPath);
156
+
157
+ var apsKey = EntitlementKeys[Entitlement.ApsEnv];
158
+ if ((entitlements & Entitlement.ApsEnv) != 0 && entitlementsPlist.root[apsKey] == null)
159
+ entitlementsPlist.root.SetString(apsKey, "development");
160
+
161
+ var groupsKey = EntitlementKeys[Entitlement.AppGroups];
162
+ if ((entitlements & Entitlement.AppGroups) != 0) {
163
+ var groups = entitlementsPlist.root[groupsKey] == null
164
+ ? entitlementsPlist.root.CreateArray(groupsKey)
165
+ : entitlementsPlist.root[groupsKey].AsArray();
166
+
167
+ var group = $"group.{PlayerSettings.applicationIdentifier}.onesignal";
168
+ if (groups.values.All(elem => elem.AsString() != group))
169
+ groups.AddString(group);
170
+ }
171
+
172
+ entitlementsPlist.WriteToFile(entitlementsPath);
173
+
174
+ // Copy the entitlement file to the xcode project
175
+ var entitlementFileName = Path.GetFileName(entitlementsPath);
176
+ var relativeDestination = targetName + "/" + entitlementFileName;
177
+
178
+ // Add the pbx configs to include the entitlements files on the project
179
+ _project.AddFile(relativeDestination, entitlementFileName);
180
+ _project.AddBuildProperty(targetGuid, "CODE_SIGN_ENTITLEMENTS", relativeDestination);
181
+ }
182
+
183
+ private void UpdateEntitlements(Entitlement entitlements)
184
+ => UpdateEntitlements(entitlements, _project.GetMainTargetGuid(), _project.GetMainTargetName());
185
+
186
+ private void AddPushCapability(string targetGuid, string targetName) {
187
+ _project.AddCapability(targetGuid, PBXCapabilityType.PushNotifications);
188
+ _project.AddCapability(targetGuid, PBXCapabilityType.BackgroundModes);
189
+
190
+ var entitlementsPath = GetEntitlementsPath(targetGuid, targetName);
191
+ // NOTE: ProjectCapabilityManager's 4th constructor param requires Unity 2019.3+
192
+ var projCapability = new ProjectCapabilityManager(_projectPath, entitlementsPath, targetName);
193
+ projCapability.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications);
194
+ projCapability.WriteToFile();
195
+ }
196
+
197
+ private void AddPushCapability() =>
198
+ AddPushCapability(_project.GetMainTargetGuid(), _project.GetMainTargetName());
199
+
200
+ /// <summary>
201
+ /// Create and add the notification extension to the project
202
+ /// </summary>
203
+ private void AddNotificationServiceExtension() {
204
+ #if !UNITY_CLOUD_BUILD
205
+ // If file exists then the below has been completed before from another build
206
+ // The below will not be updated on Append builds
207
+ // Changes would most likely need to be made to support Append builds
208
+ if (ExtensionCreatePlist(_outputPath))
209
+ return;
210
+
211
+ var extensionGuid = _project.AddAppExtension(_project.GetMainTargetGuid(),
212
+ ServiceExtensionTargetName,
213
+ PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS) + "." + ServiceExtensionTargetName,
214
+ ServiceExtensionTargetName + "/" + "Info.plist" // Unix path as it's used by Xcode
215
+ );
216
+
217
+ ExtensionAddSourceFiles(extensionGuid);
218
+
219
+ // Makes it so that the extension target is Universal (not just iPhone) and has an iOS 10 deployment target
220
+ _project.SetBuildProperty(extensionGuid, "TARGETED_DEVICE_FAMILY", "1,2");
221
+ _project.SetBuildProperty(extensionGuid, "IPHONEOS_DEPLOYMENT_TARGET", "10.0");
222
+ _project.SetBuildProperty(extensionGuid, "SWIFT_VERSION", "5.0");
223
+ _project.SetBuildProperty(extensionGuid, "ARCHS", "arm64");
224
+ _project.SetBuildProperty(extensionGuid, "DEVELOPMENT_TEAM", PlayerSettings.iOS.appleDeveloperTeamID);
225
+
226
+ _project.AddBuildProperty(extensionGuid, "LIBRARY_SEARCH_PATHS",
227
+ $"$(PROJECT_DIR)/Libraries/{PluginLibrariesPath.Replace("\\", "/")}");
228
+ _project.WriteToFile(_projectPath);
229
+
230
+ UpdateEntitlements(Entitlement.AppGroups, extensionGuid, ServiceExtensionTargetName);
231
+ #endif
232
+ }
233
+
234
+ /// <summary>
235
+ /// Add the swift source file required by the notification extension
236
+ /// </summary>
237
+ private void ExtensionAddSourceFiles(string extensionGuid) {
238
+ var buildPhaseID = _project.AddSourcesBuildPhase(extensionGuid);
239
+ var sourcePath = Path.Combine(PluginFilesPath, ServiceExtensionFilename);
240
+ var destPathRelative = Path.Combine(ServiceExtensionTargetName, ServiceExtensionFilename);
241
+
242
+ var destPath = Path.Combine(_outputPath, destPathRelative);
243
+ if (!File.Exists(destPath))
244
+ FileUtil.CopyFileOrDirectory(sourcePath.Replace("\\", "/"), destPath.Replace("\\", "/"));
245
+
246
+ var sourceFileGuid = _project.AddFile(destPathRelative, destPathRelative);
247
+ _project.AddFileToBuildSection(extensionGuid, buildPhaseID, sourceFileGuid);
248
+ }
249
+
250
+ /// <summary>
251
+ /// Create a .plist file for the extension
252
+ /// </summary>
253
+ /// <remarks>NOTE: File in Xcode project is replaced everytime, never appends</remarks>
254
+ private bool ExtensionCreatePlist(string path) {
255
+ var extensionPath = Path.Combine(path, ServiceExtensionTargetName);
256
+ Directory.CreateDirectory(extensionPath);
257
+
258
+ var plistPath = Path.Combine(extensionPath, "Info.plist");
259
+ var alreadyExists = File.Exists(plistPath);
260
+
261
+ var notificationServicePlist = new PlistDocument();
262
+ notificationServicePlist.ReadFromFile(Path.Combine(PluginFilesPath, "Info.plist"));
263
+ notificationServicePlist.root.SetString("CFBundleShortVersionString", PlayerSettings.bundleVersion);
264
+ notificationServicePlist.root.SetString("CFBundleVersion", PlayerSettings.iOS.buildNumber);
265
+
266
+ notificationServicePlist.WriteToFile(plistPath);
267
+
268
+ return alreadyExists;
269
+ }
270
+
271
+ private void ExtensionAddPodsToTarget() {
272
+ var podfilePath = Path.Combine(_outputPath, "Podfile");
273
+
274
+ if (!File.Exists(podfilePath)) {
275
+ Debug.LogError($"Could not find Podfile. {ServiceExtensionFilename} will have errors.");
276
+ return;
277
+ }
278
+
279
+ var podfile = File.ReadAllText(podfilePath);
280
+
281
+ var extensionEntryRegex = new Regex($@"target '{ServiceExtensionTargetName}' do\n(.+)\nend");
282
+ if (extensionEntryRegex.IsMatch(podfile))
283
+ return;
284
+
285
+ podfile += $"target '{ServiceExtensionTargetName}' do\n pod 'OneSignalXCFramework', '~> 3.8.1'\nend\n";
286
+ File.WriteAllText(podfilePath, podfile);
287
+ }
288
+ }
289
+ }
@@ -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 2021 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,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 2021 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
@@ -0,0 +1,99 @@
1
+ /*
2
+ * Modified MIT License
3
+ *
4
+ * Copyright 2021 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.Runtime.InteropServices;
29
+
30
+ namespace OneSignalSDK {
31
+ /// <summary>
32
+ ///
33
+ /// </summary>
34
+ public sealed partial class OneSignalIOS : OneSignal {
35
+ /*
36
+ * Global callbacks
37
+ */
38
+
39
+ [DllImport("__Internal")] private static extern void _setNotificationReceivedCallback(NotificationWillShowInForegroundDelegate callback);
40
+ [DllImport("__Internal")] private static extern void _setNotificationOpenedCallback(StringListenerDelegate callback);
41
+
42
+ [DllImport("__Internal")] private static extern void _setInAppMessageWillDisplayCallback(StringListenerDelegate callback);
43
+ [DllImport("__Internal")] private static extern void _setInAppMessageDidDisplayCallback(StringListenerDelegate callback);
44
+ [DllImport("__Internal")] private static extern void _setInAppMessageWillDismissCallback(StringListenerDelegate callback);
45
+ [DllImport("__Internal")] private static extern void _setInAppMessageDidDismissCallback(StringListenerDelegate callback);
46
+ [DllImport("__Internal")] private static extern void _setInAppMessageClickedCallback(StringListenerDelegate callback);
47
+
48
+ [DllImport("__Internal")] private static extern void _setPermissionStateChangedCallback(StateListenerDelegate callback);
49
+ [DllImport("__Internal")] private static extern void _setSubscriptionStateChangedCallback(StateListenerDelegate callback);
50
+ [DllImport("__Internal")] private static extern void _setEmailSubscriptionStateChangedCallback(StateListenerDelegate callback);
51
+ [DllImport("__Internal")] private static extern void _setSMSSubscriptionStateChangedCallback(StateListenerDelegate callback);
52
+
53
+ /*
54
+ * Direct methods
55
+ */
56
+
57
+ [DllImport("__Internal")] private static extern string _getDeviceState();
58
+
59
+ [DllImport("__Internal")] private static extern void _setLogLevel(int logLevel, int alertLevel);
60
+ [DllImport("__Internal")] private static extern void _setPrivacyConsent(bool consent);
61
+ [DllImport("__Internal")] private static extern bool _getPrivacyConsent();
62
+ [DllImport("__Internal")] private static extern void _setRequiresPrivacyConsent(bool required);
63
+ [DllImport("__Internal")] private static extern bool _getRequiresPrivacyConsent();
64
+ [DllImport("__Internal")] private static extern void _initialize(string appId);
65
+ [DllImport("__Internal")] private static extern void _promptForPushNotificationsWithUserResponse(int hashCode, BooleanResponseDelegate callback);
66
+ [DllImport("__Internal")] private static extern void _postNotification(string optionsJson, int hashCode, StringResponseDelegate callback);
67
+ [DllImport("__Internal")] private static extern void _setTrigger(string key, string value);
68
+ [DllImport("__Internal")] private static extern void _setTriggers(string triggersJson);
69
+ [DllImport("__Internal")] private static extern void _removeTrigger(string key);
70
+ [DllImport("__Internal")] private static extern void _removeTriggers(string triggersJson);
71
+ [DllImport("__Internal")] private static extern string _getTrigger(string key);
72
+ [DllImport("__Internal")] private static extern string _getTriggers();
73
+ [DllImport("__Internal")] private static extern void _setInAppMessagesArePaused(bool paused);
74
+ [DllImport("__Internal")] private static extern bool _getInAppMessagesArePaused();
75
+
76
+ [DllImport("__Internal")] private static extern void _sendTag(string name, string value, int hashCode, BooleanResponseDelegate callback);
77
+ [DllImport("__Internal")] private static extern void _sendTags(string tagsJson, int hashCode, BooleanResponseDelegate callback);
78
+ [DllImport("__Internal")] private static extern void _getTags(int hashCode, StringResponseDelegate callback);
79
+ [DllImport("__Internal")] private static extern void _deleteTag(string name, int hashCode, BooleanResponseDelegate callback);
80
+ [DllImport("__Internal")] private static extern void _deleteTags(string tagsJson, int hashCode, BooleanResponseDelegate callback);
81
+
82
+ [DllImport("__Internal")] private static extern void _setExternalUserId(string externalId, string authHash, int hashCode, BooleanResponseDelegate callback);
83
+ [DllImport("__Internal")] private static extern void _setEmail(string email, string authHash, int hashCode, BooleanResponseDelegate callback);
84
+ [DllImport("__Internal")] private static extern void _setSMSNumber(string smsNumber, string authHash, int hashCode, BooleanResponseDelegate callback);
85
+
86
+ [DllImport("__Internal")] private static extern void _logoutEmail(int hashCode, BooleanResponseDelegate callback);
87
+ [DllImport("__Internal")] private static extern void _logoutSMSNumber(int hashCode, BooleanResponseDelegate callback);
88
+
89
+ [DllImport("__Internal")] private static extern void _setLanguage(string languageCode, int hashCode, BooleanResponseDelegate callback);
90
+
91
+ [DllImport("__Internal")] private static extern void _promptLocation();
92
+ [DllImport("__Internal")] private static extern void _setShareLocation(bool share);
93
+ [DllImport("__Internal")] private static extern bool _getShareLocation();
94
+
95
+ [DllImport("__Internal")] private static extern void _sendOutcome(string name, int hashCode, BooleanResponseDelegate callback);
96
+ [DllImport("__Internal")] private static extern void _sendUniqueOutcome(string name, int hashCode, BooleanResponseDelegate callback);
97
+ [DllImport("__Internal")] private static extern void _sendOutcomeWithValue(string name, float value, int hashCode, BooleanResponseDelegate callback);
98
+ }
99
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 58d98a3bf598402ca24a771f7e37c3b3
3
+ timeCreated: 1631805035