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

参数

proj扩展方法的隐式 this 参数。
mainTargetGuid要将手表扩展关联到的主目标的 GUID。
watchExtensionTargetGuid[[AddWatchExtension()]] 返回的手表扩展的 GUID。
name手表应用程序的名称。该名称必须与手表扩展的名称相同。
bundleId手表应用程序的 Bundle ID。
infoPlistPath手表应用程序 Info.plist 文档的路径。

返回

string 新目标的 GUID。

描述

创建一个手表应用程序。

using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
using UnityEditor.iOS.Xcode.Extensions;
using UnityEngine;

public class SetupWatchExtension { [PostProcessBuild] private static void PostProcessBuild_iOS(BuildTarget target, string buildPath) { PBXProject proj = new PBXProject(); string projPath = PBXProject.GetPBXProjectPath(buildPath); proj.ReadFromFile(projPath); string mainTarget = proj.TargetGuidByName(PBXProject.GetUnityTargetName()); string watchExtensionTargetGuid = PBXProjectExtensions.AddWatchExtension(proj, mainTarget, "watchtest Extension", "com.unity3d.watchtest.watchkitapp.watchkitextension", "watchtest Extension/Info.plist"); string watchAppTargetGuid = PBXProjectExtensions.AddWatchApp(proj, mainTarget, watchExtensionTargetGuid, "watchtest", "com.unity3d.watchtest.watchkitapp", "watchtest/Info.plist");

FileUtil.CopyFileOrDirectory("Assets/Plugins/iOSWatchAppFiles/watchtest", Path.Combine(buildPath, "watchtest")); FileUtil.CopyFileOrDirectory("Assets/Plugins/iOSWatchAppFiles/watchtest Extension", Path.Combine(buildPath, "watchtest Extension"));

var filesToBuild = new List<string> { "watchtest/Interface.storyboard", "watchtest/Assets.xcassets", };

foreach (var path in filesToBuild) { var fileGuid = proj.AddFile(path, path); proj.AddFileToBuild(watchAppTargetGuid, fileGuid); }

filesToBuild = new List<string> { "watchtest Extension/Assets.xcassets",

"watchtest Extension/ExtensionDelegate.h", "watchtest Extension/ExtensionDelegate.m", "watchtest Extension/InterfaceController.h", "watchtest Extension/InterfaceController.m", "watchtest Extension/NotificationController.h", "watchtest Extension/NotificationController.m", };

foreach (var path in filesToBuild) { var fileGuid = proj.AddFile(path, path); proj.AddFileToBuild(watchExtensionTargetGuid, fileGuid); }

var filesToAdd = new List<string> { "watchtest/Info.plist", "watchtest Extension/PushNotificationPayload.apns", "watchtest Extension/Info.plist", };

foreach (var path in filesToAdd) proj.AddFile(path, path);

proj.WriteToFile(projPath); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961