1
+ using UnityEngine ;
2
+ using UnityEditor ;
3
+ using UnityEditor . Callbacks ;
4
+ using System . Collections ;
5
+ using System . IO ;
6
+
7
+ #if UNITY_IPHONE && UNITY_EDITOR
8
+
9
+ public struct framework {
10
+ public string name ;
11
+ public string id ;
12
+ public string fileId ;
13
+
14
+ public framework ( string fName , string fId , string fFileid ) {
15
+ name = fName ;
16
+ id = fId ;
17
+ fileId = fFileid ;
18
+ }
19
+ }
20
+
21
+ /*
22
+ Adds required frameworks (currently just UserNotifications.framework) to the iOS project
23
+ To add further frameworks in the build process, just add a new framework to the Frameworks array
24
+ */
25
+
26
+ public class PostBuildTrigger {
27
+
28
+ [ PostProcessBuild ]
29
+ public static void OnPostProcessBuild ( BuildTarget target , string pathToBuiltProject ) {
30
+ LinkLibraries ( target , pathToBuiltProject ) ;
31
+ }
32
+
33
+ public static void LinkLibraries ( BuildTarget target , string pathToBuiltProject ) {
34
+ framework [ ] frameworksToAdd = new framework [ 1 ] ;
35
+
36
+ frameworksToAdd [ 0 ] = new framework ( "UserNotifications" , "CAF63D112040CD8E00A651DC" , "CAF63D102040CD8E00A651DC" ) ;
37
+
38
+ string projectFile = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj" ;
39
+ string contents = File . ReadAllText ( projectFile ) ;
40
+
41
+ foreach ( framework framework in frameworksToAdd ) {
42
+ AddFrameworkToProject ( framework , ref contents ) ;
43
+ }
44
+
45
+ File . WriteAllText ( projectFile , contents ) ;
46
+ }
47
+
48
+ public static void AddFrameworkToProject ( framework framework , ref string contents ) {
49
+ string orientationSupport = "Ref = 8AC71EC319E7FBA90027502F /* OrientationSupport.mm */; };" ;
50
+ string pbxFileReference = "wnFileType = text.plist.xml; path = Info.plist; sourceTree = \" <group>\" ; };" ;
51
+ string pbsFrameworksBuildPhase = "1D60589F0D05DD5A006BFB54 /* Foundation.framework in Frameworks */," ;
52
+ string frameworksSection = "1D30AB110D05D00D00671497 /* Foundation.framework */," ;
53
+
54
+ contents = contents . Replace ( orientationSupport , orientationSupport + "\n \t \t " + framework . id + " /* " + framework . name + ".framework in Frameworks */ = {isa = PBXBuildFile; fileRef = " + framework . fileId + " /* " + framework . name + ".framework */; };" ) ;
55
+ contents = contents . Replace ( pbxFileReference , pbxFileReference + "\n \t \t " + framework . fileId + " /* " + framework . name + ".framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = " + framework . name + ".framework; path = System/Library/Frameworks/" + framework . name + ".framework; sourceTree = SDKROOT; };" ) ;
56
+ contents = contents . Replace ( pbsFrameworksBuildPhase , framework . id + " /* " + framework . name + ".framework in Frameworks */,\n \t \t \t \t " + pbsFrameworksBuildPhase ) ;
57
+ contents = contents . Replace ( frameworksSection , framework . fileId + " /* " + framework . name + ".framework */,\n \t \t \t \t " + frameworksSection ) ;
58
+ }
59
+ }
60
+
61
+ #endif
0 commit comments