[펌] Enable Push Notification in XCode project by default?
Unity3D/Script / 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
반응형
'Unity3D > Script' 카테고리의 다른 글
XCode-Capabilities-Push Notifications를 기본 ON 하는 방법 (0) | 2019.06.04 |
---|---|
[펌] Unity5のPostProcessBuildでXcode Capabilityの設定する方法 (0) | 2019.06.03 |
[펌] animation.sample() usage (0) | 2019.05.09 |
[펌] 타임서버에서 시각 가져와서 Unity 에서 사용하기 (NST, NIST) (0) | 2019.04.15 |
[펌] Async-Await instead of coroutines in Unity 2017 (0) | 2019.02.21 |