블로그 이미지
Every unexpected event is a path to learning for you. blueasa

카테고리

분류 전체보기 (2795)
Unity3D (852)
Programming (478)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (185)
협업 (61)
3DS Max (3)
Game (12)
Utility (68)
Etc (98)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (55)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday

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:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  3. <plist version="1.0">
  4. <dict>
  5. <key>aps-environment</key>
  6. <string>development</string>
  7. </dict>
  8. </plist>

Now you can add this script on the Editor folder:

  1. using System.IO;
  2. using JetBrains.Annotations;
  3. using UnityEditor;
  4. using UnityEditor.Callbacks;
  5. using UnityEditor.iOS.Xcode;
  6. using UnityEngine;
  7.  
  8. public class PostProcessBuildScript : ScriptableObject
  9. {
  10. public DefaultAsset entitlementsFile;
  11.  
  12. [PostProcessBuild, UsedImplicitly]
  13. public static void ChangesToXcode(BuildTarget buildTarget, string pathToBuiltProject)
  14. {
  15. // Get project PBX file
  16. var projPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);
  17. var proj = new PBXProject();
  18. proj.ReadFromString(File.ReadAllText(projPath));
  19. var target = proj.TargetGuidByName("Unity-iPhone");
  20.  
  21. // Create an instance of this ScriptableObject so we can point to its entitlements file
  22. var dummy = CreateInstance<PostProcessBuildScript>();
  23. var entitlementsFile = dummy.entitlementsFile;
  24. DestroyImmediate(dummy);
  25. if (entitlementsFile != null)
  26. {
  27. // Copy the entitlement file to the xcode project
  28. var entitlementPath = AssetDatabase.GetAssetPath(entitlementsFile);
  29. var entitlementFileName = Path.GetFileName(entitlementPath);
  30. var unityTarget = PBXProject.GetUnityTargetName();
  31. var relativeDestination = unityTarget + "/" + entitlementFileName;
  32. FileUtil.CopyFileOrDirectory(entitlementPath, pathToBuiltProject + "/" + relativeDestination);
  33.  
  34. // Add the pbx configs to include the entitlements files on the project
  35. proj.AddFile(relativeDestination, entitlementFileName);
  36. proj.AddBuildProperty(target, "CODE_SIGN_ENTITLEMENTS", relativeDestination);
  37.  
  38. // Add push notifications as a capability on the target
  39. proj.AddBuildProperty(target, "SystemCapabilities", "{com.apple.Push = {enabled = 1;};}");
  40. }
  41.  
  42. // Save the changed configs to the file
  43. File.WriteAllText(projPath, proj.WriteToString());
  44. }
  45. }

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

 

반응형
Posted by blueasa
, |