1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . IO ;
3
4
using System . Runtime . InteropServices ;
4
5
using UnityEditor ;
5
6
using UnityEditor . Callbacks ;
@@ -18,14 +19,26 @@ namespace UNKO.Unity_Builder
18
19
[ StructLayout ( LayoutKind . Auto ) ] // ignore codacy
19
20
public class iOSBuildConfig : BuildConfigBase
20
21
{
22
+ private const string entitlements = @"
23
+ <?xml version=""1.0"" encoding=""UTF-8\""?>
24
+ <!DOCTYPE plist PUBLIC ""-//Apple//DTD PLIST 1.0//EN"" ""http://www.apple.com/DTDs/PropertyList-1.0.dtd"">
25
+ <plist version=""1.0"">
26
+ <dict>
27
+ <key>aps-environment</key>
28
+ <string>production</string>
29
+ </dict>
30
+ </plist>" ;
31
+
32
+ const string UNITY_IPHONE = "Unity-iPhone" ;
33
+
21
34
[ PostProcessBuild ( 999 ) ]
22
35
public static void OnPostProcessBuild ( BuildTarget buildTarget , string path )
23
36
{
24
37
bool platformIsiOS = buildTarget == BuildTarget . iOS ;
25
38
if ( platformIsiOS )
26
39
{
27
40
#if UNITY_IOS
28
- string projectPath = path + "/Unity-iPhone .xcodeproj/project.pbxproj";
41
+ string projectPath = path + $ "/ { UNITY_IPHONE } .xcodeproj/project.pbxproj";
29
42
30
43
PBXProject pbxProject = new PBXProject ( ) ;
31
44
pbxProject . ReadFromFile ( projectPath ) ;
@@ -51,18 +64,24 @@ public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
51
64
Debug . LogError ( $ "plist Can't open, path:{ infoPlistPath } ") ;
52
65
}
53
66
67
+ // https://lhamed.github.io/66th-post-copy-2/
68
+ var fileName = "unity.entitlements" ; // 이거없으면 푸시 안됩니다
69
+ var targetGUID = pbxProject . TargetGuidByName ( UNITY_IPHONE ) ;
70
+ var entitlementsFilePath = $ "{ path } /{ UNITY_IPHONE } /{ fileName } ";
71
+ try
72
+ {
73
+ File . WriteAllText ( entitlementsFilePath , entitlements ) ;
74
+ pbxProject . AddFile ( $ "{ UNITY_IPHONE } /{ fileName } ", fileName ) ;
75
+ pbxProject . AddBuildProperty ( targetGUID , "CODE_SIGN_ENTITLEMENTS" , UNITY_IPHONE + "/" + fileName ) ;
76
+ pbxProject . WriteToFile ( projectPath ) ;
77
+ }
78
+ catch ( IOException e )
79
+ {
80
+ Debug . Log ( "Could not copy entitlements. Probably already exists. " + e ) ;
81
+ }
54
82
55
- // 출처:https://forum.unity.com/threads/how-do-i-enable-remote-push-notification-capability-using-unity-cloud-build.457812/
56
- // get entitlements path
57
- string [ ] idArray = Application . identifier . Split ( '.' ) ;
58
- var entitlementsPath = $ "Unity-iPhone/{ idArray [ idArray . Length - 1 ] } .entitlements";
59
-
60
- var capManager = new ProjectCapabilityManager ( projectPath , entitlementsPath , "Unity-iPhone" ) ;
61
-
62
- // ITMS-90078: Missing Push Notification Entitlement
63
- capManager . AddBackgroundModes ( BackgroundModesOptions . BackgroundFetch ) ;
64
- capManager . AddBackgroundModes ( BackgroundModesOptions . RemoteNotifications ) ;
65
- capManager . WriteToFile ( ) ;
83
+ ProjectCapabilityManager pcm = new ProjectCapabilityManager ( projectPath , entitlementsFilePath , UNITY_IPHONE ) ;
84
+ pcm . AddPushNotifications ( false ) ;
66
85
#endif
67
86
}
68
87
0 commit comments