Skip to content

Commit 2c8b23c

Browse files
committed
2019.3.9 broke AddFileToBuild so moved to AddFileToBuildSection
* Fixes #287
1 parent 326c1c3 commit 2c8b23c

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

OneSignalExample/Assets/OneSignal/Editor/PostProcessBuildPlayer_iOS.cs

+22-9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public static class BuildPostProcessor
4646
{
4747
public static readonly string DEFAULT_PROJECT_TARGET_NAME = "Unity-iPhone";
4848
public static readonly string NOTIFICATION_SERVICE_EXTENSION_TARGET_NAME = "OneSignalNotificationServiceExtension";
49+
public static readonly string NOTIFICATION_SERVICE_EXTENSION_OBJECTIVEC_FILENAME = "NotificationService";
4950

5051
private static readonly char DIR_CHAR = Path.DirectorySeparatorChar;
5152
public static readonly string OS_PLATFORM_LOCATION = "Assets" + DIR_CHAR + "OneSignal" + DIR_CHAR + "Platforms" + DIR_CHAR;
@@ -211,7 +212,7 @@ private static void AddPushCapability(PBXProject project, string path, string ta
211212

212213
private static void AddNotificationServiceExtension(PBXProject project, string path)
213214
{
214-
#if UNITY_2017_2_OR_NEWER && !UNITY_CLOUD_BUILD
215+
#if UNITY_2017_2_OR_NEWER && !UNITY_CLOUD_BUILD
215216
var projectPath = PBXProject.GetPBXProjectPath(path);
216217
var mainTargetGUID = GetPBXProjectTargetGUID(project);
217218
var extensionTargetName = NOTIFICATION_SERVICE_EXTENSION_TARGET_NAME;
@@ -231,9 +232,7 @@ private static void AddNotificationServiceExtension(PBXProject project, string p
231232
extensionTargetName + "/" + "Info.plist" // Unix path as it's used by Xcode
232233
);
233234

234-
var sourceDestination = extensionTargetName + "/NotificationService";
235-
project.AddFileToBuild(extensionGUID, project.AddFile(sourceDestination + ".h", sourceDestination + ".h", PBXSourceTree.Source));
236-
project.AddFileToBuild(extensionGUID, project.AddFile(sourceDestination + ".m", sourceDestination + ".m", PBXSourceTree.Source));
235+
AddNotificationServiceSourceFilesToTarget(project, extensionGUID, path);
237236

238237
foreach(var framework in FRAMEWORKS_TO_ADD) {
239238
project.AddFrameworkToProject(extensionGUID, framework, true);
@@ -245,10 +244,6 @@ private static void AddNotificationServiceExtension(PBXProject project, string p
245244

246245
project.SetBuildProperty(extensionGUID, "ARCHS", "$(ARCHS_STANDARD)");
247246
project.SetBuildProperty(extensionGUID, "DEVELOPMENT_TEAM", PlayerSettings.iOS.appleDeveloperTeamID);
248-
249-
foreach(var type in new string[] { "m", "h" })
250-
if (!File.Exists(path + DIR_CHAR + sourceDestination + "." + type))
251-
FileUtil.CopyFileOrDirectory(OS_PLATFORM_LOCATION + "iOS" + DIR_CHAR + "NotificationService." + type, path + DIR_CHAR + sourceDestination + "." + type);
252247

253248
project.AddBuildProperty(extensionGUID, "LIBRARY_SEARCH_PATHS", "$(PROJECT_DIR)/Libraries/OneSignal/Platforms/iOS");
254249
project.WriteToFile(projectPath);
@@ -268,8 +263,26 @@ private static void AddNotificationServiceExtension(PBXProject project, string p
268263
extensionTargetName,
269264
new HashSet<EntitlementOptions> { EntitlementOptions.AppGroups }
270265
);
271-
#endif
266+
#endif
267+
}
268+
269+
// Copies NotificationService.m and .h files into the OneSignalNotificationServiceExtension folder adds them to the Xcode target
270+
private static void AddNotificationServiceSourceFilesToTarget(PBXProject project, string extensionGUID, string path)
271+
{
272+
var buildPhaseID = project.AddSourcesBuildPhase(extensionGUID);
273+
foreach (var type in new string[] { "m", "h" }) {
274+
var nativeFileName = NOTIFICATION_SERVICE_EXTENSION_OBJECTIVEC_FILENAME + "." + type;
275+
var sourcePath = OS_PLATFORM_LOCATION + "iOS" + DIR_CHAR + nativeFileName;
276+
var nativeFileRelativeDestination = NOTIFICATION_SERVICE_EXTENSION_TARGET_NAME + "/" + nativeFileName;
277+
278+
var destPath = path + DIR_CHAR + nativeFileRelativeDestination;
279+
if (!File.Exists(destPath))
280+
FileUtil.CopyFileOrDirectory(sourcePath, destPath);
281+
282+
var sourceFileGUID = project.AddFile(nativeFileRelativeDestination, nativeFileRelativeDestination, PBXSourceTree.Source);
283+
project.AddFileToBuildSection(extensionGUID, buildPhaseID, sourceFileGUID);
272284
}
285+
}
273286

274287
// Create a .plist file for the NSE
275288
// NOTE: File in Xcode project is replaced everytime, never appends

0 commit comments

Comments
 (0)