com.onesignal.unity.ios 2.14.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 (35) hide show
  1. package/Documentation~/com.onesignal.unity.ios.md +4 -0
  2. package/Editor/OneSignal.iOS.Editor.asmdef +14 -0
  3. package/Editor/OneSignal.iOS.Editor.asmdef.meta +7 -0
  4. package/Editor/PostProcessBuildPlayer_iOS.cs +399 -0
  5. package/Editor/PostProcessBuildPlayer_iOS.cs.meta +13 -0
  6. package/Editor.meta +8 -0
  7. package/LICENSE.md +129 -0
  8. package/LICENSE.md.meta +7 -0
  9. package/README.md +5 -0
  10. package/README.md.meta +7 -0
  11. package/Runtime/AssemblyInfo.cs +3 -0
  12. package/Runtime/AssemblyInfo.cs.meta +11 -0
  13. package/Runtime/OneSignal.iOS.asmdef +17 -0
  14. package/Runtime/OneSignal.iOS.asmdef.meta +7 -0
  15. package/Runtime/OneSignalIOS.cs +458 -0
  16. package/Runtime/OneSignalIOS.cs.meta +10 -0
  17. package/Runtime/OneSignalIOSInit.cs +12 -0
  18. package/Runtime/OneSignalIOSInit.cs.meta +3 -0
  19. package/Runtime/Plugins/iOS/Info.plist +31 -0
  20. package/Runtime/Plugins/iOS/Info.plist.meta +9 -0
  21. package/Runtime/Plugins/iOS/NotificationService.h +13 -0
  22. package/Runtime/Plugins/iOS/NotificationService.h.meta +26 -0
  23. package/Runtime/Plugins/iOS/NotificationService.m +40 -0
  24. package/Runtime/Plugins/iOS/NotificationService.m.meta +36 -0
  25. package/Runtime/Plugins/iOS/OneSignal.h +617 -0
  26. package/Runtime/Plugins/iOS/OneSignal.h.meta +26 -0
  27. package/Runtime/Plugins/iOS/OneSignalUnityRuntime.m +542 -0
  28. package/Runtime/Plugins/iOS/OneSignalUnityRuntime.m.meta +24 -0
  29. package/Runtime/Plugins/iOS/libOneSignal.a +0 -0
  30. package/Runtime/Plugins/iOS/libOneSignal.a.meta +21 -0
  31. package/Runtime/Plugins/iOS.meta +9 -0
  32. package/Runtime/Plugins.meta +8 -0
  33. package/Runtime.meta +8 -0
  34. package/package.json +35 -0
  35. package/package.json.meta +7 -0
@@ -0,0 +1,4 @@
1
+ # OneSignal Unity SDK - iOS
2
+ Check out the [README](https://github.com/OneSignal/OneSignal-Unity-SDK/README.md) in our GitHub repository.
3
+
4
+ Full documentation available at [documentation.onesignal.com](https://documentation.onesignal.com/docs/unity-sdk-setup)
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "OneSignal.iOS.Editor",
3
+ "references": [],
4
+ "optionalUnityReferences": [],
5
+ "includePlatforms": [
6
+ "Editor"
7
+ ],
8
+ "excludePlatforms": [],
9
+ "allowUnsafeCode": false,
10
+ "overrideReferences": false,
11
+ "precompiledReferences": [],
12
+ "autoReferenced": false,
13
+ "defineConstraints": []
14
+ }
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: 1d1c6a283b2a6462892c58ef830733ae
3
+ AssemblyDefinitionImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
@@ -0,0 +1,399 @@
1
+ /*
2
+ * Adds required frameworks to the iOS project, and adds the OneSignalNotificationServiceExtension
3
+ * Also handles making sure both targets (app and extension service) have the correct dependencies
4
+ */
5
+
6
+ /*
7
+ * Testing Notes
8
+ * When making any changes please test the following senerios
9
+ * 1. Building to a new directory
10
+ * 2. Appending. Running a 2nd time
11
+ * 2. Appending. Comming from the last released version
12
+ * 3. Appending. Comming from a project without OneSignal
13
+ *
14
+ * In each of the tests ensure the NSE + App Groups work by doing the following:
15
+ * 1. Send a notification with Badge set to Increase by 1
16
+ * 2. Send a 2nd identical notification
17
+ * 3. Observe Badge value on device as 2. (NSE is working)
18
+ * 4. Open app and then background it again, Badge value will be cleared.
19
+ * 5. Send a 3rd identical notification.
20
+ * 6. Observe Badge value is 1. (If it is 3 there is an App Group issue)
21
+ */
22
+
23
+ // Flag if an App Group should created for the main target and the NSE
24
+ // Try renaming NOTIFICATION_SERVICE_EXTENSION_TARGET_NAME below first before
25
+ // removing ADD_APP_GROUP if you run into Provisioning errors in Xcode that
26
+ // can't be fix.
27
+ // ADD_APP_GROUP is required for;
28
+ // Outcomes, Badge Increment, and possibly for future features
29
+
30
+ #define ADD_APP_GROUP
31
+
32
+ #if UNITY_IPHONE && UNITY_EDITOR
33
+
34
+ using System.IO;
35
+ using System;
36
+ using UnityEngine;
37
+ using UnityEditor;
38
+ using UnityEditor.Callbacks;
39
+ using UnityEditor.iOS.Xcode;
40
+ using System.Text;
41
+ using System.Collections.Generic;
42
+ using UnityEditor.iOS.Xcode.Extensions;
43
+
44
+
45
+ public static class BuildPostProcessor
46
+ {
47
+ public const string DefaultProjectTargetName = "Unity-iPhone";
48
+ public const string NotificationServiceExtensionTargetName = "OneSignalNotificationServiceExtension";
49
+ public const string NotificationServiceExtensionObjCFilename = "NotificationService";
50
+ public const string PackageName = "com.onesignal.unity.ios";
51
+
52
+ public static readonly string PluginLibrariesPath = Path.Combine(PackageName, "Runtime", "Plugins", "iOS");
53
+ public static readonly string PluginFilesPath = Path.Combine("Packages", PluginLibrariesPath);
54
+
55
+ private static readonly string[] FrameworksToAdd =
56
+ {
57
+ "NotificationCenter.framework",
58
+ "UserNotifications.framework",
59
+ "UIKit.framework",
60
+ "SystemConfiguration.framework",
61
+ "CoreGraphics.framework",
62
+ "WebKit.framework"
63
+ };
64
+
65
+ private enum EntitlementOptions
66
+ {
67
+ ApsEnv,
68
+ AppGroups
69
+ }
70
+
71
+ /*
72
+ * Unity 2019.3 made large changes to the Xcode build system / API.
73
+ * There is now two targets;
74
+ * - Unity-Iphone (Main)
75
+ * - UnityFramework
76
+ * - Plugins are now added this instead of the main target
77
+ */
78
+ #if UNITY_2019_3_OR_NEWER
79
+ /// <remarks>
80
+ /// var projectUUID = project.GetUnityMainTargetGuid();
81
+ /// return project.GetBuildPhaseName(projectUUID);
82
+ /// The above always returns null, using a static value for now.
83
+ /// </remarks>
84
+ private static string GetPBXProjectTargetName(PBXProject project)
85
+ => DefaultProjectTargetName;
86
+
87
+ private static string GetPBXProjectTargetGUID(PBXProject project)
88
+ => project.GetUnityMainTargetGuid();
89
+
90
+ private static string GetPBXProjectUnityFrameworkGUID(PBXProject project)
91
+ => project.GetUnityFrameworkTargetGuid();
92
+ #else
93
+ private static string GetPBXProjectTargetName(PBXProject project)
94
+ => PBXProject.GetUnityTargetName();
95
+
96
+ private static string GetPBXProjectTargetGUID(PBXProject project)
97
+ => project.TargetGuidByName(PBXProject.GetUnityTargetName());
98
+
99
+ private static string GetPBXProjectUnityFrameworkGUID(PBXProject project)
100
+ => GetPBXProjectTargetGUID(project);
101
+ #endif
102
+
103
+ [PostProcessBuildAttribute(1)]
104
+ public static void OnPostProcessBuild(BuildTarget target, string path)
105
+ {
106
+ if (target != BuildTarget.iOS)
107
+ return;
108
+
109
+ var projectPath = PBXProject.GetPBXProjectPath(path);
110
+ var project = new PBXProject();
111
+
112
+ project.ReadFromString(File.ReadAllText(projectPath));
113
+
114
+ var mainTargetName = GetPBXProjectTargetName(project);
115
+ var mainTargetGUID = GetPBXProjectTargetGUID(project);
116
+ var unityFrameworkGUID = GetPBXProjectUnityFrameworkGUID(project);
117
+
118
+ foreach (var framework in FrameworksToAdd)
119
+ {
120
+ project.AddFrameworkToProject(unityFrameworkGUID, framework, false);
121
+ }
122
+
123
+ AddOrUpdateEntitlements(
124
+ path,
125
+ project,
126
+ mainTargetGUID,
127
+ mainTargetName,
128
+ new HashSet<EntitlementOptions>
129
+ {
130
+ EntitlementOptions.ApsEnv, EntitlementOptions.AppGroups
131
+ }
132
+ );
133
+
134
+ // Add the NSE target to the Xcode project
135
+ AddNotificationServiceExtension(project, path);
136
+
137
+ // Reload file after changes from AddNotificationServiceExtension
138
+ project.WriteToFile(projectPath);
139
+ var contents = File.ReadAllText(projectPath);
140
+ project.ReadFromString(contents);
141
+
142
+ // Add push notifications as a capability on the main app target
143
+ AddPushCapability(project, path, mainTargetGUID, mainTargetName);
144
+
145
+ File.WriteAllText(projectPath, project.WriteToString());
146
+ }
147
+
148
+ // Returns exisiting file if found, otherwises provides a default name to use
149
+ private static string GetEntitlementsPath(string projectPath, PBXProject project, string targetGUI, string targetName)
150
+ {
151
+ // Check if there is already an eltitlements file configured in the Xcode project
152
+ #if UNITY_2018_2_OR_NEWER
153
+ var relativeEntitlementPath = project.GetBuildPropertyForConfig(targetGUI, "CODE_SIGN_ENTITLEMENTS");
154
+ if (relativeEntitlementPath != null)
155
+ {
156
+ var entitlementPath = Path.Combine(projectPath, relativeEntitlementPath);
157
+ if (File.Exists(entitlementPath))
158
+ return entitlementPath;
159
+ }
160
+ #endif
161
+
162
+ // No existing file, use a new name
163
+ return Path.Combine(projectPath, targetName, $"{targetName}.entitlements");
164
+ }
165
+
166
+ private static void AddOrUpdateEntitlements(string path, PBXProject project, string targetGUI,
167
+ string targetName,
168
+ HashSet<EntitlementOptions> options)
169
+ {
170
+ string entitlementPath = GetEntitlementsPath(path, project, targetGUI, targetName);
171
+ var entitlements = new PlistDocument();
172
+
173
+ // Check if the file already exisits and read it
174
+ if (File.Exists(entitlementPath))
175
+ {
176
+ entitlements.ReadFromFile(entitlementPath);
177
+ }
178
+
179
+ if (options.Contains(EntitlementOptions.ApsEnv))
180
+ {
181
+ if (entitlements.root["aps-environment"] == null)
182
+ entitlements.root.SetString("aps-environment", "development");
183
+ }
184
+
185
+ // TOOD: This can be updated to use project.AddCapability() in the future
186
+ #if ADD_APP_GROUP
187
+ if (options.Contains(EntitlementOptions.AppGroups) &&
188
+ entitlements.root["com.apple.security.application-groups"] == null)
189
+ {
190
+ var groups = entitlements.root.CreateArray("com.apple.security.application-groups");
191
+ groups.AddString("group." + PlayerSettings.applicationIdentifier + ".onesignal");
192
+ }
193
+ #endif
194
+
195
+ entitlements.WriteToFile(entitlementPath);
196
+
197
+ // Copy the entitlement file to the xcode project
198
+ var entitlementFileName = Path.GetFileName(entitlementPath);
199
+ var relativeDestination = targetName + "/" + entitlementFileName;
200
+
201
+ // Add the pbx configs to include the entitlements files on the project
202
+ project.AddFile(relativeDestination, entitlementFileName);
203
+ project.AddBuildProperty(targetGUI, "CODE_SIGN_ENTITLEMENTS", relativeDestination);
204
+ }
205
+
206
+ private static void AddPushCapability(PBXProject project, string path, string targetGUID, string targetName)
207
+ {
208
+ var projectPath = PBXProject.GetPBXProjectPath(path);
209
+ project.AddCapability(targetGUID, PBXCapabilityType.PushNotifications);
210
+ project.AddCapability(targetGUID, PBXCapabilityType.BackgroundModes);
211
+
212
+ var entitlementsPath = GetEntitlementsPath(path, project, targetGUID, targetName);
213
+ // NOTE: ProjectCapabilityManager's 4th constructor param requires Unity 2019.3+
214
+ var projCapability = new ProjectCapabilityManager(projectPath, entitlementsPath, targetName);
215
+ projCapability.AddBackgroundModes(BackgroundModesOptions.RemoteNotifications);
216
+ projCapability.WriteToFile();
217
+ }
218
+
219
+ private static void AddNotificationServiceExtension(PBXProject project, string path)
220
+ {
221
+ #if !UNITY_CLOUD_BUILD
222
+ var projectPath = PBXProject.GetPBXProjectPath(path);
223
+ var mainTargetGUID = GetPBXProjectTargetGUID(project);
224
+ var extensionTargetName = NotificationServiceExtensionTargetName;
225
+
226
+ var exisitingPlistFile = CreateNotificationExtensionPlistFile(path);
227
+ // If file exisits then the below has been completed before from another build
228
+ // The below will not be updated on Append builds
229
+ // Changes would most likely need to be made to support Append builds
230
+ if (exisitingPlistFile)
231
+ return;
232
+
233
+ var extensionGUID = PBXProjectExtensions.AddAppExtension(
234
+ project,
235
+ mainTargetGUID,
236
+ extensionTargetName,
237
+ PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS) + "." + extensionTargetName,
238
+ extensionTargetName + "/" + "Info.plist" // Unix path as it's used by Xcode
239
+ );
240
+
241
+ AddNotificationServiceSourceFilesToTarget(project, extensionGUID, path);
242
+
243
+ foreach (var framework in FrameworksToAdd)
244
+ {
245
+ project.AddFrameworkToProject(extensionGUID, framework, true);
246
+ }
247
+
248
+ // Makes it so that the extension target is Universal (not just iPhone) and has an iOS 10 deployment target
249
+ project.SetBuildProperty(extensionGUID, "TARGETED_DEVICE_FAMILY", "1,2");
250
+ project.SetBuildProperty(extensionGUID, "IPHONEOS_DEPLOYMENT_TARGET", "10.0");
251
+ project.SetBuildProperty(extensionGUID, "ARCHS", "$(ARCHS_STANDARD)");
252
+ project.SetBuildProperty(extensionGUID, "DEVELOPMENT_TEAM", PlayerSettings.iOS.appleDeveloperTeamID);
253
+
254
+ project.AddBuildProperty(extensionGUID, "LIBRARY_SEARCH_PATHS",
255
+ $"$(PROJECT_DIR)/Libraries/{PluginLibrariesPath.Replace("\\", "/")}");
256
+ project.WriteToFile(projectPath);
257
+
258
+ // Add libOneSignal.a to the OneSignalNotificationServiceExtension target
259
+ var contents = File.ReadAllText(projectPath);
260
+
261
+ // This method only modifies the PBXProject string passed in (contents).
262
+ // After this method finishes, we must write the contents string to disk
263
+ InsertStaticFrameworkIntoTargetBuildPhaseFrameworks("libOneSignal", "CD84C25F20742FAB0035D524",
264
+ extensionGUID,
265
+ ref contents, project);
266
+ File.WriteAllText(projectPath, contents);
267
+
268
+ AddOrUpdateEntitlements(
269
+ path,
270
+ project,
271
+ extensionGUID,
272
+ extensionTargetName,
273
+ new HashSet<EntitlementOptions> {EntitlementOptions.AppGroups}
274
+ );
275
+ #endif
276
+ }
277
+
278
+ // Copies NotificationService.m and .h files into the OneSignalNotificationServiceExtension folder adds them to the Xcode target
279
+ private static void AddNotificationServiceSourceFilesToTarget(PBXProject project, string extensionGUID,
280
+ string projectPath)
281
+ {
282
+ var buildPhaseID = project.AddSourcesBuildPhase(extensionGUID);
283
+ foreach (var type in new string[] {"m", "h"})
284
+ {
285
+ var fileName = $"{NotificationServiceExtensionObjCFilename}.{type}";
286
+ var sourcePath = Path.Combine(PluginFilesPath, fileName);
287
+
288
+ var destPathRelative = Path.Combine(NotificationServiceExtensionTargetName, fileName);
289
+ var destPath = Path.Combine(projectPath, destPathRelative);
290
+ if (!File.Exists(destPath))
291
+ FileUtil.CopyFileOrDirectory(sourcePath.Replace("\\", "/"), destPath.Replace("\\", "/"));
292
+
293
+ var sourceFileGUID = project.AddFile(destPathRelative, destPathRelative);
294
+ project.AddFileToBuildSection(extensionGUID, buildPhaseID, sourceFileGUID);
295
+ }
296
+ }
297
+
298
+ // Create a .plist file for the NSE
299
+ // NOTE: File in Xcode project is replaced everytime, never appends
300
+ private static bool CreateNotificationExtensionPlistFile(string projectPath)
301
+ {
302
+ var pathToNotificationService = Path.Combine(projectPath, NotificationServiceExtensionTargetName);
303
+ Directory.CreateDirectory(pathToNotificationService);
304
+
305
+ var notificationServicePlistPath = Path.Combine(pathToNotificationService, "Info.plist");
306
+ bool exisiting = File.Exists(notificationServicePlistPath);
307
+
308
+ // Read from the OneSignal plist template file.
309
+ var notificationServicePlist = new PlistDocument();
310
+ notificationServicePlist.ReadFromFile(Path.Combine(PluginFilesPath, "Info.plist"));
311
+ notificationServicePlist.root.SetString("CFBundleShortVersionString", PlayerSettings.bundleVersion);
312
+ notificationServicePlist.root.SetString("CFBundleVersion", PlayerSettings.iOS.buildNumber);
313
+ notificationServicePlist.WriteToFile(notificationServicePlistPath);
314
+ return exisiting;
315
+ }
316
+
317
+ // Takes a static framework that is already linked to a different target in the project and links it to the specified target
318
+ private static void InsertStaticFrameworkIntoTargetBuildPhaseFrameworks(string staticFrameworkName,
319
+ string frameworkGuid, string target, ref string contents, PBXProject project)
320
+ {
321
+ #if !UNITY_CLOUD_BUILD
322
+ // In order to find the fileRef, find the PBXBuildFile objects section of the PBXProject
323
+ var splitString = " /* " + staticFrameworkName + ".a in Frameworks */ = {isa = PBXBuildFile; fileRef = ";
324
+ var splitComponents = contents.Split(new string[] {splitString}, StringSplitOptions.None);
325
+
326
+ if (splitComponents.Length < 2)
327
+ {
328
+ Debug.LogError(
329
+ "(error 1) OneSignal's Build Post Processor has encountered an error while attempting to add the Notification Extension Service to your project. Please create an issue on our OneSignal-Unity-SDK repo on GitHub.");
330
+ return;
331
+ }
332
+
333
+ var afterSplit = splitComponents[1];
334
+
335
+ // To get the fileRef of the static framework, read the last 24 characters of the beforeSplit string
336
+ var fileRefBuilder = new StringBuilder();
337
+
338
+ for (int i = 0; i < 24; i++)
339
+ {
340
+ fileRefBuilder.Append(afterSplit[i]);
341
+ }
342
+
343
+ var fileRef = fileRefBuilder.ToString();
344
+
345
+ project.AddFileToBuild(target, fileRef);
346
+
347
+ // Add the framework as an additional object in PBXBuildFile objects
348
+ contents = contents.Replace("; fileRef = " + fileRef + " /* " + staticFrameworkName + ".a */; };",
349
+ "; fileRef = " + fileRef + " /* " + staticFrameworkName + ".a */; };\n\t\t" + frameworkGuid + " /* " +
350
+ staticFrameworkName + ".a in Frameworks */ = {isa = PBXBuildFile; fileRef = " + fileRef + " /* " +
351
+ staticFrameworkName + ".a */; };");
352
+
353
+ // Find the build phase ID number
354
+ var targetBuildPhaseId = project.GetFrameworksBuildPhaseByTarget(target);
355
+ string[] components =
356
+ contents.Split(
357
+ new string[]
358
+ {
359
+ targetBuildPhaseId +
360
+ " /* Frameworks */ = {\n\t\t\tisa = PBXFrameworksBuildPhase;\n\t\t\tbuildActionMask = "
361
+ }, StringSplitOptions.None);
362
+
363
+ if (components.Length < 2)
364
+ {
365
+ Debug.LogError(
366
+ "(error 2) OneSignal's Build Post Processor has encountered an error while attempting to add the Notification Extension Service to your project. Please create an issue on our OneSignal-Unity-SDK repo on GitHub.");
367
+ return;
368
+ }
369
+
370
+ var buildPhaseString = components[1];
371
+
372
+ var replacer = new StringBuilder();
373
+
374
+ for (int i = 0; i < buildPhaseString.Length; i++)
375
+ {
376
+ var seq = buildPhaseString[i];
377
+
378
+ if (char.IsNumber(seq))
379
+ {
380
+ replacer.Append(seq);
381
+ }
382
+ else
383
+ {
384
+ break;
385
+ }
386
+ }
387
+
388
+ // insert the framework into the PBXFrameworksBuildPhase
389
+ var beginString = targetBuildPhaseId +
390
+ " /* Frameworks */ = {\n\t\t\tisa = PBXFrameworksBuildPhase;\n\t\t\tbuildActionMask = " +
391
+ replacer.ToString() + ";\n\t\t\tfiles = (";
392
+ contents = contents.Replace(beginString,
393
+ beginString + "\n" + "\t\t\t\t" + frameworkGuid + " /* " + staticFrameworkName +
394
+ ".a in Frameworks */,");
395
+ #endif
396
+ }
397
+ }
398
+
399
+ #endif
@@ -0,0 +1,13 @@
1
+ fileFormatVersion: 2
2
+ guid: 590499923d4dc432c8657d9a0672e954
3
+ timeCreated: 1519426331
4
+ licenseType: Free
5
+ MonoImporter:
6
+ externalObjects: {}
7
+ serializedVersion: 2
8
+ defaultReferences: []
9
+ executionOrder: 0
10
+ icon: {instanceID: 0}
11
+ userData:
12
+ assetBundleName:
13
+ assetBundleVariant:
package/Editor.meta ADDED
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: f8bbcc76d5e8d4a14b0ca2561fd09537
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant: