Last active
September 22, 2024 13:02
-
-
Save th3d0g/5c898ba569ceae16cd4353ba30636f75 to your computer and use it in GitHub Desktop.
Unity PostProcessBuid script for editing the PList file within the Xcode project. This example will enable push notifcations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using UnityEngine; | |
| using UnityEditor; | |
| using UnityEditor.Callbacks; | |
| using System.Collections; | |
| #if UNITY_IOS | |
| using UnityEditor.iOS.Xcode; | |
| #endif | |
| using System.IO; | |
| // PListiOS - Edit the PList file. | |
| public class PListiOS | |
| { | |
| #if UNITY_CLOUD_BUILD | |
| // This method is added in the Advanced Features Settings on UCB | |
| // PostBuildProcessor.OnPostprocessBuildiOS | |
| public static void OnPostprocessBuildiOS (string exportPath) | |
| { | |
| Debug.Log("[UCB] OnPostprocessBuildiOS"); | |
| ProcessPostBuild(BuildTarget.iPhone,exportPath); | |
| } | |
| #endif | |
| [PostProcessBuild] | |
| public static void OnPostprocessBuild (BuildTarget buildTarget, string path) | |
| { | |
| #if !UNITY_CLOUD_BUILD | |
| Debug.Log ("[iOS] OnPostprocessBuild"); | |
| ProcessPostBuild (buildTarget, path); | |
| #endif | |
| } | |
| public static void ProcessPostBuild(BuildTarget buildTarget, string path) | |
| { | |
| #if UNITY_IOS | |
| if (buildTarget == BuildTarget.iOS) { | |
| Debug.Log ("[iOS] OnPostprocessBuild - PList"); | |
| // Get plist | |
| string plistPath = path + "/Info.plist"; | |
| PlistDocument plist = new PlistDocument(); | |
| plist.ReadFromString(File.ReadAllText(plistPath)); | |
| // Get root | |
| PlistElementDict rootDict = plist.root; | |
| // Change value of CFBundleVersion in Xcode plist | |
| var buildKey = "UIBackgroundModes"; | |
| rootDict.CreateArray (buildKey).AddString ("remote-notification"); | |
| // Write to file | |
| File.WriteAllText(plistPath, plist.WriteToString()); | |
| } | |
| #endif | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment