forked from onevcat/XUPorter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXCodePostProcess.cs
executable file
·107 lines (80 loc) · 3.22 KB
/
XCodePostProcess.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.XCodeEditor;
#endif
using System.IO;
public static class XCodePostProcess
{
#if UNITY_EDITOR
[PostProcessBuild(999)]
public static void OnPostProcessBuild( BuildTarget target, string pathToBuiltProject )
{
if (target != BuildTarget.iPhone) {
Debug.LogWarning("Target is not iPhone. XCodePostProcess will not run");
return;
}
//得到xcode工程的路径
string path = Path.GetFullPath (pathToBuiltProject);
// Create a new project object from build target
XCProject project = new XCProject (pathToBuiltProject);
// Find and run through all projmods files to patch the project.
// Please pay attention that ALL projmods files in your project folder will be excuted!
//在这里面把frameworks添加在你的xcode工程里面
string[] files = Directory.GetFiles (Application.dataPath, "*.projmods", SearchOption.AllDirectories);
foreach (string file in files) {
project.ApplyMod (file);
}
//增加一个编译标记。。没有的话sharesdk会报错。。
project.AddOtherLinkerFlags("-licucore");
//设置签名的证书, 第二个参数 你可以设置成你的证书
project.overwriteBuildSetting ("CODE_SIGN_IDENTITY", "xxxxxx", "Release");
project.overwriteBuildSetting ("CODE_SIGN_IDENTITY", "xxxxxx", "Debug");
// 编辑plist 文件
EditorPlist(path);
//编辑代码文件
EditorCode(path);
// Finally save the xcode project
project.Save ();
}
private static void EditorPlist(string filePath)
{
XCPlist list =new XCPlist(filePath);
string bundle = "com.yusong.momo";
string PlistAdd = @"
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLIconFile</key>
<string>Icon@2x</string>
<key>CFBundleURLName</key>
<string>"+bundle+@"</string>
<key>CFBundleURLSchemes</key>
<array>
<string>ww123456</string>
</array>
</dict>
</array>";
//在plist里面增加一行
list.AddKey(PlistAdd);
//在plist里面替换一行
list.ReplaceKey("<string>com.yusong.${PRODUCT_NAME}</string>","<string>"+bundle+"</string>");
//保存
list.Save();
}
private static void EditorCode(string filePath)
{
//读取UnityAppController.mm文件
XClass UnityAppController = new XClass(filePath + "/Classes/UnityAppController.mm");
//在指定代码后面增加一行代码
UnityAppController.WriteBelow("#include \"PluginBase/AppDelegateListener.h\"","#import <ShareSDK/ShareSDK.h>");
//在指定代码中替换一行
UnityAppController.Replace("return YES;","return [ShareSDK handleOpenURL:url sourceApplication:sourceApplication annotation:annotation wxDelegate:nil];");
//在指定代码后面增加一行
UnityAppController.WriteBelow("UnityCleanup();\n}","- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url\r{\r return [ShareSDK handleOpenURL:url wxDelegate:nil];\r}");
}
#endif
}