Unity3D/Script
[펌] Enable Push Notification in XCode project by default?
blueasa
2019. 6. 3. 17:42
I manage to get it working by a C# script, but since this build setting need an .entitlementfile in your xcode project, first you will need to create a text file called [projectName].entitlement anywhere in your project with this content:
- <?xml version="1.0" encoding="UTF-8"?>
- http://www.apple.com/DTDs/PropertyList-1.0.dtd">
- <plist version="1.0">
- <dict>
- <key>aps-environment</key>
- <string>development</string>
- </dict>
- </plist>
Now you can add this script on the Editor folder:
- using System.IO;
- using JetBrains.Annotations;
- using UnityEditor;
- using UnityEditor.Callbacks;
- using UnityEditor.iOS.Xcode;
- using UnityEngine;
- public class PostProcessBuildScript : ScriptableObject
- {
- public DefaultAsset entitlementsFile;
- [PostProcessBuild, UsedImplicitly]
- public static void ChangesToXcode(BuildTarget buildTarget, string pathToBuiltProject)
- {
- // Get project PBX file
- var projPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);
- var proj = new PBXProject();
- proj.ReadFromString(File.ReadAllText(projPath));
- var target = proj.TargetGuidByName("Unity-iPhone");
- // Create an instance of this ScriptableObject so we can point to its entitlements file
- var dummy = CreateInstance<PostProcessBuildScript>();
- var entitlementsFile = dummy.entitlementsFile;
- DestroyImmediate(dummy);
- if (entitlementsFile != null)
- {
- // Copy the entitlement file to the xcode project
- var entitlementPath = AssetDatabase.GetAssetPath(entitlementsFile);
- var entitlementFileName = Path.GetFileName(entitlementPath);
- var unityTarget = PBXProject.GetUnityTargetName();
- var relativeDestination = unityTarget + "/" + entitlementFileName;
- FileUtil.CopyFileOrDirectory(entitlementPath, pathToBuiltProject + "/" + relativeDestination);
- // Add the pbx configs to include the entitlements files on the project
- proj.AddFile(relativeDestination, entitlementFileName);
- proj.AddBuildProperty(target, "CODE_SIGN_ENTITLEMENTS", relativeDestination);
- // Add push notifications as a capability on the target
- proj.AddBuildProperty(target, "SystemCapabilities", "{com.apple.Push = {enabled = 1;};}");
- }
- // Save the changed configs to the file
- File.WriteAllText(projPath, proj.WriteToString());
- }
- }
After that you just define the entitlementsFile variable for the script in the inspector window and you should now have the push notification activated by default when you build for iOS.
[출처] https://answers.unity.com/questions/1224123/enable-push-notification-in-xcode-project-by-defau.html
Enable Push Notification in XCode project by default? - Unity Answers
answers.unity.com
반응형