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

Parámetros

proj The implicit this parameter for the extension method.
mainTargetGuid The GUID of the main target to link the watch extension to.
watchExtensionTargetGuid The GUID of watch extension as returned by [[AddWatchExtension()]].
name The name of the watch app. It must the same as the name of the watch extension.
bundleId The bundle ID of the watch app.
infoPlistPath Path to the watch app Info.plist document.

Valor de retorno

string The GUID of the new target.

Descripción

Creates a watch application.

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