2021-08-23 09:28:14 +08:00
|
|
|
|
|
2021-08-24 17:50:14 +08:00
|
|
|
|
#if UNITY_IOS && UNITY_EDITOR
|
2021-08-23 09:28:14 +08:00
|
|
|
|
using UnityEditor;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEditor.Callbacks;
|
|
|
|
|
|
using UnityEditor.iOS.Xcode;
|
2021-12-10 18:10:20 +08:00
|
|
|
|
|
2021-08-23 09:28:14 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
public static class XCodePostProcessBuild
|
|
|
|
|
|
{
|
|
|
|
|
|
#if UNITY_IOS && UNITY_EDITOR
|
|
|
|
|
|
private static readonly string[] csAddFrameworks = new string[]{
|
|
|
|
|
|
"Security.framework","WebKit.framework", "CoreGraphics.framework"
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
[PostProcessBuild(1)]
|
|
|
|
|
|
public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuiltProject)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (BuildTarget.iOS != buildTarget)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
string projectPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
|
|
|
|
|
|
SetFrameworksAndBuildSettings(projectPath);
|
2021-09-14 11:14:51 +08:00
|
|
|
|
SetInfoList(pathToBuiltProject, "com.ZhiXingPai.PowerFun", "wxe3573a84e7e29902");
|
2021-08-23 09:28:14 +08:00
|
|
|
|
SetAssociatedDomains(projectPath, "wx.powerfun.com.cn");
|
2021-12-10 18:10:20 +08:00
|
|
|
|
Assets.NativeLocale.AddLocalizedStringsIOS(pathToBuiltProject, Path.Combine(Application.dataPath, "Editor/Locale"));
|
2021-08-23 09:28:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
private static void SetFrameworksAndBuildSettings(string path)
|
|
|
|
|
|
{
|
|
|
|
|
|
PBXProject proj = new PBXProject();
|
|
|
|
|
|
proj.ReadFromString(File.ReadAllText(path));
|
|
|
|
|
|
string target = proj.GetUnityMainTargetGuid();
|
|
|
|
|
|
Debug.Log("Target Name is " + target);
|
|
|
|
|
|
// 设置 BuildSettings
|
|
|
|
|
|
proj.AddBuildProperty(target, "Other Linker Flags", "-Objc -all_load");
|
|
|
|
|
|
proj.SetBuildProperty(target, "ENABLE_BITCODE", "NO");
|
|
|
|
|
|
|
|
|
|
|
|
//根据微信SDK文档的要求,加入相关的Frameworks
|
|
|
|
|
|
for (int i = 0; i < csAddFrameworks.Length; ++i)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!proj.ContainsFramework(target, csAddFrameworks[i]))
|
|
|
|
|
|
proj.AddFrameworkToProject(target, csAddFrameworks[i], false);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-12-17 18:28:02 +08:00
|
|
|
|
//苹果登录配置项
|
|
|
|
|
|
//proj.AddCapability(target, PBXCapabilityType.SignInWithApple);
|
|
|
|
|
|
proj.AddFrameworkToProject(proj.GetUnityFrameworkTargetGuid(), "AuthenticationServices.framework", false);
|
|
|
|
|
|
|
2021-08-23 09:28:14 +08:00
|
|
|
|
File.WriteAllText(path, proj.WriteToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void SetInfoList(string buildPath, string wxUrlName, string wxScheme)
|
|
|
|
|
|
{
|
|
|
|
|
|
string listPath = buildPath + "/Info.plist";
|
|
|
|
|
|
PlistDocument plist = new PlistDocument();
|
|
|
|
|
|
plist.ReadFromString(File.ReadAllText(listPath));
|
|
|
|
|
|
|
|
|
|
|
|
// 在“info”标签栏的“URL type“添加“URL scheme”,值为你在微信后台注册的应用程序的 AppID
|
|
|
|
|
|
PlistElementArray urlArray = plist.root.CreateArray("CFBundleURLTypes");
|
|
|
|
|
|
PlistElementDict dict = urlArray.AddDict();
|
|
|
|
|
|
dict.SetString("CFBundleTypeRole", "Editor");
|
|
|
|
|
|
dict.SetString("CFBundleURLName", wxUrlName);
|
|
|
|
|
|
PlistElementArray urlSchemes = dict.CreateArray("CFBundleURLSchemes");
|
|
|
|
|
|
urlSchemes.AddString(wxScheme);
|
2021-09-14 11:14:51 +08:00
|
|
|
|
PlistElementDict dictMine = urlArray.AddDict();
|
|
|
|
|
|
dictMine.SetString("CFBundleTypeRole", "Editor");
|
|
|
|
|
|
dictMine.SetString("CFBundleURLName", "powerfunx");
|
|
|
|
|
|
PlistElementArray urlSchemesMine = dictMine.CreateArray("CFBundleURLSchemes");
|
|
|
|
|
|
urlSchemesMine.AddString("powerfunx");
|
2021-08-23 09:28:14 +08:00
|
|
|
|
|
|
|
|
|
|
// 在 “info”标签栏的“LSApplicationQueriesSchemes“添加weixin wechat和weixinULAPI
|
|
|
|
|
|
PlistElementArray wxArray = plist.root.CreateArray("LSApplicationQueriesSchemes");
|
|
|
|
|
|
wxArray.AddString("weixin");
|
|
|
|
|
|
wxArray.AddString("wechat");
|
|
|
|
|
|
wxArray.AddString("weixinULAPI");
|
2021-08-26 15:08:02 +08:00
|
|
|
|
wxArray.AddString("powerfun");
|
2021-09-17 18:50:50 +08:00
|
|
|
|
// 设置转向
|
2021-09-17 20:21:35 +08:00
|
|
|
|
//var orientations = plist.root.CreateArray("UISupportedInterfaceOrientations");
|
|
|
|
|
|
//orientations.AddString("UIInterfaceOrientationLandscapeRight");
|
|
|
|
|
|
//orientations.AddString("UIInterfaceOrientationLandscapeLeft");
|
2021-08-23 09:28:14 +08:00
|
|
|
|
|
|
|
|
|
|
PlistElementDict qxLoc = plist.root.CreateDict("NSLocationWhenInUseUsageDescription");
|
|
|
|
|
|
qxLoc.SetBoolean("NSLocationWhenInUseUsageDescription", true);
|
2021-10-18 14:03:26 +08:00
|
|
|
|
plist.root.SetString("NSCameraUsageDescription","Use the camera to scan the QR code or take a photo or take a video to upload.");
|
|
|
|
|
|
plist.root.SetString("NSPhotoLibraryUsageDescription", "Need to access your image file to upload.");
|
|
|
|
|
|
plist.root.SetString("NSLocationWhenInUseUsageDescription", "Need to get your geographic location in order to push the route for you.");
|
2021-09-15 10:45:11 +08:00
|
|
|
|
plist.root.SetBoolean("ITSAppUsesNonExemptEncryption", false);
|
2021-08-23 09:28:14 +08:00
|
|
|
|
File.WriteAllText(listPath, plist.WriteToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 设置Associated Domains
|
|
|
|
|
|
public static void SetAssociatedDomains(string pbxProjectPath, string domainUrl)
|
|
|
|
|
|
{
|
|
|
|
|
|
//默认 Target Name, 你自己的可能不一样
|
|
|
|
|
|
string targetName = "Unity-iPhone";
|
|
|
|
|
|
//Set the entitlements file name to what you want but make sure it has this extension
|
|
|
|
|
|
string entitlementsFileName = "my_app.entitlements";
|
|
|
|
|
|
|
|
|
|
|
|
var entitlements = new ProjectCapabilityManager(pbxProjectPath, entitlementsFileName, targetName);
|
|
|
|
|
|
entitlements.AddAssociatedDomains(new string[] { "applinks:" + domainUrl });
|
2021-12-17 18:28:02 +08:00
|
|
|
|
//苹果登录
|
|
|
|
|
|
entitlements.AddSignInWithApple();
|
2021-08-23 09:28:14 +08:00
|
|
|
|
entitlements.WriteToFile();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|