移动端微信接入
This commit is contained in:
1 parent
ca91f45ef3
commit
31e8e3bebb
32 files changed
+17241
-9
No files matched your search
@@ -0,0 +1,92 @@
|
||||
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_IOS && UNITY_EDITOR
|
||||
using UnityEditor.Callbacks;
|
||||
using UnityEditor.iOS.Xcode;
|
||||
#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);
|
||||
SetInfoList(pathToBuiltProject, "com.ZhiXingPai.PowerFun", "wx9146e6697a6aef2d");
|
||||
SetAssociatedDomains(projectPath, "wx.powerfun.com.cn");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// 在 “info”标签栏的“LSApplicationQueriesSchemes“添加weixin wechat和weixinULAPI
|
||||
PlistElementArray wxArray = plist.root.CreateArray("LSApplicationQueriesSchemes");
|
||||
wxArray.AddString("weixin");
|
||||
wxArray.AddString("wechat");
|
||||
wxArray.AddString("weixinULAPI");
|
||||
|
||||
PlistElementDict qxLoc = plist.root.CreateDict("NSLocationWhenInUseUsageDescription");
|
||||
qxLoc.SetBoolean("NSLocationWhenInUseUsageDescription", true);
|
||||
|
||||
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 });
|
||||
|
||||
entitlements.WriteToFile();
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84ef3790c38d9564cb7770687283c42d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in new issue
Block a user