public static string AddAppExtension (iOS.Xcode.PBXProject proj, string mainTargetGuid, string name, string bundleId, string infoPlistPath);

参数

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); } }