Skip to content

Commit bdd962c

Browse files
authored
Platform-Dependent Directory Separator Character (#139)
• Switches away from using hardcoded directory separator characters to using platform-dependent separators in the build script and update checker script
1 parent 1ecf8b6 commit bdd962c

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

OneSignalExample/Assets/OneSignal/Editor/OneSignalEditorCheckUpdateScript.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,14 @@ IEnumerator FetchCurrentVersion(string url)
9797
//since there was an error, we shouldn't attempt to serialize data from the request
9898
yield break;
9999
}
100+
101+
var separator = Path.DirectorySeparatorChar;
100102

101103
//parse JSON to extract the latest version
102104
var json = Json.Deserialize(request.downloadHandler.text) as System.Collections.Generic.Dictionary<string, object>;
103105

104106
var latestVersionString = (json["tag_name"] as string);
105-
var currentVersionString = File.ReadAllText("Assets/OneSignal/VERSION").Replace("\n", "");
107+
var currentVersionString = File.ReadAllText("Assets" + separator + "OneSignal" + separator + "VERSION").Replace("\n", "");
106108

107109
//remove . to convert "2.8.2" to "282" for example
108110
var latestVersion = int.Parse(latestVersionString.Replace(".", ""));

OneSignalExample/Assets/OneSignal/Editor/PostProcessBuildPlayer_iOS.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public class BuildPostProcessor
2525
[PostProcessBuildAttribute(1)]
2626
public static void OnPostProcessBuild(BuildTarget target, string path)
2727
{
28+
var separator = Path.DirectorySeparatorChar;
29+
2830
string projectPath = PBXProject.GetPBXProjectPath(path);
2931
PBXProject project = new PBXProject();
3032

@@ -34,13 +36,14 @@ public static void OnPostProcessBuild(BuildTarget target, string path)
3436

3537
// UserNotifications.framework is required by libOneSignal.a
3638
project.AddFrameworkToProject(targetGUID, "UserNotifications.framework", false);
37-
39+
3840
#if UNITY_2017_2_OR_NEWER && !UNITY_CLOUD_BUILD
39-
41+
42+
var platformsLocation = "Assets" + separator + "OneSignal" + separator + "Platforms" + separator;
4043
var extensionTargetName = "OneSignalNotificationServiceExtension";
41-
var pathToNotificationService = path + "/" + extensionTargetName;
44+
var pathToNotificationService = path + separator + extensionTargetName;
4245

43-
var notificationServicePlistPath = pathToNotificationService + "/Info.plist";
46+
var notificationServicePlistPath = pathToNotificationService + separator + "Info.plist";
4447

4548
//if this is a rebuild, we've already added the extension service, no need to run this script a second time
4649
if (File.Exists(notificationServicePlistPath))
@@ -49,13 +52,13 @@ public static void OnPostProcessBuild(BuildTarget target, string path)
4952
Directory.CreateDirectory(pathToNotificationService);
5053

5154
PlistDocument notificationServicePlist = new PlistDocument();
52-
notificationServicePlist.ReadFromFile ("Assets/OneSignal/Platforms/iOS/Info.plist");
55+
notificationServicePlist.ReadFromFile (platformsLocation + "iOS" + separator + "Info.plist");
5356
notificationServicePlist.root.SetString ("CFBundleShortVersionString", PlayerSettings.bundleVersion);
5457
notificationServicePlist.root.SetString ("CFBundleVersion", PlayerSettings.iOS.buildNumber.ToString ());
5558

5659
var notificationServiceTarget = PBXProjectExtensions.AddAppExtension (project, targetGUID, extensionTargetName, PlayerSettings.GetApplicationIdentifier (BuildTargetGroup.iOS) + "." + extensionTargetName, notificationServicePlistPath);
5760

58-
var sourceDestination = extensionTargetName + "/NotificationService";
61+
var sourceDestination = extensionTargetName + separator + "NotificationService";
5962

6063
project.AddFileToBuild (notificationServiceTarget, project.AddFile (sourceDestination + ".h", sourceDestination + ".h", PBXSourceTree.Source));
6164
project.AddFileToBuild (notificationServiceTarget, project.AddFile (sourceDestination + ".m", sourceDestination + ".m", PBXSourceTree.Source));
@@ -76,8 +79,8 @@ public static void OnPostProcessBuild(BuildTarget target, string path)
7679
notificationServicePlist.WriteToFile (notificationServicePlistPath);
7780

7881
foreach (string type in new string[] { "m", "h" })
79-
if (!File.Exists(path + "/" + sourceDestination + "." + type))
80-
FileUtil.CopyFileOrDirectory("Assets/OneSignal/Platforms/iOS/NotificationService.h", path + "/" + sourceDestination + "." + type);
82+
if (!File.Exists(path + separator + sourceDestination + "." + type))
83+
FileUtil.CopyFileOrDirectory(platformsLocation + "iOS" + separator + "NotificationService.h", path + separator + sourceDestination + "." + type);
8184

8285
project.WriteToFile (projectPath);
8386

@@ -97,7 +100,7 @@ public static void OnPostProcessBuild(BuildTarget target, string path)
97100

98101
// enable the Notifications capability in the main app target
99102
project.ReadFromString(contents);
100-
var entitlementPath = path + "/" + targetName + "/" + targetName + ".entitlements";
103+
var entitlementPath = path + separator + targetName + separator + targetName + ".entitlements";
101104

102105
PlistDocument entitlements = new PlistDocument();
103106
entitlements.root.SetString("aps-environment", "development");
@@ -112,7 +115,7 @@ public static void OnPostProcessBuild(BuildTarget target, string path)
112115
// Copy the entitlement file to the xcode project
113116
var entitlementFileName = Path.GetFileName(entitlementPath);
114117
var unityTarget = PBXProject.GetUnityTargetName();
115-
var relativeDestination = unityTarget + "/" + entitlementFileName;
118+
var relativeDestination = unityTarget + separator + entitlementFileName;
116119

117120
// Add the pbx configs to include the entitlements files on the project
118121
project.AddFile(relativeDestination, entitlementFileName);

0 commit comments

Comments
 (0)