Version: 2017.4
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

PBXProjectExtensions.AddWatchApp

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

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

Parameters

projThe implicit this parameter for the extension method.
mainTargetGuidThe GUID of the main target to link the watch extension to.
watchExtensionTargetGuidThe GUID of watch extension as returned by [[AddWatchExtension()]].
nameThe name of the watch app. It must the same as the name of the watch extension.
bundleIdThe bundle ID of the watch app.
infoPlistPathPath to the watch app Info.plist document.

Returns

string The GUID of the new target.

Description

Creates a watch application.

no example available in JavaScript
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); } }