proj | 扩展方法的隐式 this 参数。 |
mainTargetGuid | 要将应用程序关联到的主目标的 GUID。 |
name | 应用程序扩展的名称。 |
bundleId | 应用程序扩展的 Bundle ID。该 Bundle ID 必须以父应用程序的 Bundle ID 为前缀。 |
infoPlistPath | 应用程序扩展 Info.plist 文档的路径。 |
string 新目标的 GUID。
创建一个应用程序扩展。
using UnityEditor; using UnityEngine; using UnityEditor.iOS.Xcode; using UnityEditor.iOS.Xcode.Extensions; using System.IO; using UnityEditor.Callbacks;
public class ScriptBatch : MonoBehaviour { [PostProcessBuild] private static void PostProcessBuild_iOS(BuildTarget target, string buildPath) { File.Copy("Assets/extension/TodayViewController.h", buildPath + "/appext/TodayViewController.h"); File.Copy("Assets/extension/TodayViewController.m", buildPath + "/appext/TodayViewController.m");
PBXProject proj = new PBXProject(); string projPath = PBXProject.GetPBXProjectPath(buildPath); proj.ReadFromFile(projPath);
string mainTarget = proj.TargetGuidByName(PBXProject.GetUnityTargetName());
string newTarget = proj.AddAppExtension(mainTarget, "appext", "com.unity3d.product.appext", "appext/Info.plist"); proj.AddFileToBuild(newTarget, proj.AddFile(buildPath + "/appext/TodayViewController.h", "appext/TodayViewController.h")); proj.AddFileToBuild(newTarget, proj.AddFile(buildPath + "/appext/TodayViewController.m", "appext/TodayViewController.m")); proj.AddFrameworkToProject(newTarget, "NotificationCenter.framework", true); proj.WriteToFile(projPath); } }