Version: 2017.3
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); } }