watchOS 故障排除watchOS Troubleshooting

本页包含可能遇到的问题的其他信息和解决方法。This page contains additional information and workarounds for issues you may encounter.

已知问题Known Issues

常规General

  • 较早版本的 Visual Studio for Mac 错误地将AppleCompanionSettings图标之一显示为88x88 像素;如果尝试提交到 App Store,则会导致缺少图标错误Earlier releases of Visual Studio for Mac incorrectly show one of the AppleCompanionSettings icons as being 88x88 pixels; which results in a Missing Icon Error if you attempt to submit to the App Store. 此图标应为87x87 像素( @3x Retina 屏幕的29个单位)。This icon should be 87x87 pixels (29 units for @3x Retina screens). 无法在 Visual Studio for Mac 中解决此问题-请在 Xcode 中编辑图像资产,或者手动编辑内容 json文件(以与本示例匹配)。You cannot fix this in Visual Studio for Mac - either edit the image asset in Xcode or manually edit the Contents.json file (to match this sample).

  • 如果未正确设置监视扩展项目的Info.plist > WKApp 捆绑 Id与 WATCH 应用的捆绑 id相匹配,则调试器将无法连接,并且 Visual Studio for Mac 将等待消息 "等待调试程序连接 "If the Watch Extension Project's Info.plist > WKApp Bundle ID is not correctly set to match the Watch App's Bundle ID, the debugger will fail to connect and Visual Studio for Mac will wait with the message "Waiting for debugger to connect".

  • 通知模式下支持调试,但可能不可靠。Debugging is supported in Notifications mode but can be unreliable. 重试有时会起作用。Retrying will sometimes work. 确认监视应用的info.plist WKCompanionAppBundleIdentifier 设置为与 iOS 父/容器应用(即 iPhone 上运行的应用程序)的捆绑标识符相匹配。Confirm that the Watch App's Info.plist WKCompanionAppBundleIdentifier is set to match the bundle identifier of the iOS parent/container app (ie. the one that runs on the iPhone).

  • iOS 设计器不显示用于速览或通知界面控制器的入口点箭头。iOS Designer does not show entrypoint arrows for Glance or Notification interface controllers.

  • 不能将两个 WKNotificationControllers 添加到情节提要。You cannot add two WKNotificationControllers to a storyboard. 解决方法: storyboard XML 中的 notificationCategory 元素始终以相同的 id插入。Workaround: The notificationCategory element in the storyboard XML is always inserted with the same id. 若要解决此问题,你可以添加两个(或多个)通知控制器,在文本编辑器中打开情节提要文件,然后手动将 id 元素更改为唯一。To work around this problem you can add two (or more) Notification Controllers, open the storyboard file in a text editor and then manually change the id element to be unique.

  • 尝试启动应用程序时,可能会看到错误 "尚未生成应用程序"。You may see an error "The application has not been built" when trying to launch the app. 如果启动项目设置为监视扩展项目,则会在清除后出现这种情况。This occurs after a Clean when the startup project is set to the watch extension project. 解决方法是选择 "生成" > "全部重新生成",然后重新启动应用。The fix is to select Build > Rebuild All and then re-launch the app.

Visual StudioVisual Studio

对于 Watch 工具包,iOS 设计器支持要求正确配置解决方案。The iOS Designer support for Watch Kit requires the solution to be configured correctly. 如果未设置项目引用(请参阅如何设置引用),则设计图面将不能正常工作。If the project references are not set (see how to set references) then the design surface will not work correctly.

从图标图像中删除 Alpha 通道Removing the Alpha Channel from Icon Images

图标不应包含 alpha 通道(alpha 通道用于定义图像的透明区域),否则应用程序存储提交过程中将拒绝应用,错误如下:Icons should not contain an alpha channel (the alpha channel defines transparent areas of an image), otherwise the app will be rejected during App Store submission with an error similar to this:

Invalid Icon - The watch application '...watchkitextension.appex/WatchApp.app'
contains an icon file '...watchkitextension.appex/WatchApp.app/Icon-27.5@2x.png'
with an alpha channel. Icons should not have an alpha channel.

可以轻松地使用预览版应用删除 Mac OS X 上的 alpha 通道:It's easy to remove the alpha channel on Mac OS X using the Preview app:

  1. 预览中打开图标图像,然后选择 "文件" > 导出Open the icon image in Preview and then choose File > Export.

  2. 如果出现 alpha 通道,则显示的对话框将包括alpha复选框。The dialog that appears will include an Alpha checkbox if an alpha channel is present.

  3. Untick " Alpha " 复选框,并将文件保存到正确的位置。Untick the Alpha checkbox and Save the file to the correct location.

  4. 图标图像现在应传递 Apple 的验证检查。The icon image should now pass Apple's validation checks.

手动添加接口控制器文件Manually Adding Interface Controller Files

重要

Xamarin 的 WatchKit 支持包括在 iOS 设计器中设计 watch 情节提要(在 Visual Studio for Mac 和 Visual Studio 中),这不需要下述步骤。Xamarin's WatchKit support includes designing watch storyboards in the iOS designer (in both Visual Studio for Mac and Visual Studio), which does not require the steps outlined below. 只需在 "Visual Studio for Mac 属性" pad 中为接口控制器指定类名称C# ,即可自动创建代码文件。Simply give an interface controller a Class name in the Visual Studio for Mac Properties pad and the C# code files will be created automatically.

如果你使用的是 Xcode Interface Builder,请按照以下步骤为你的手表应用创建新的界面控制器并启用与 Xcode 的同步,以便可以在中C#使用插座和操作:If you are using Xcode Interface Builder, follow these steps to create new interface controllers for your watch app and enable synchronization with Xcode so that the outlets and actions are available in C#:

  1. 在 Xcode 中打开 "监视" 应用的界面。情节提要 Interface BuilderOpen the watch app's Interface.storyboard in Xcode Interface Builder.

  2. 将新 InterfaceController 拖动到情节提要上:Drag a new InterfaceController onto the storyboard:

  3. 你现在可以将控件拖到接口控制器上(例如You can now drag controls onto the interface controller (eg. 标签和按钮),但你仍无法创建插座或操作,因为不存在 .h头文件。labels and buttons) but you cannot create outlets or actions yet, because there is no .h header file. 以下步骤将导致创建所需的 .h头文件。The following steps will cause the required .h header file to be created.

  4. 关闭情节提要并返回到 Visual Studio for Mac。Close the storyboard and return to Visual Studio for Mac. 在 " C# 监视应用扩展" 项目中创建新文件MyInterfaceController.cs (或任何所需的名称)(而不是情节提要的 "监视" 应用本身)。Create a new C# file MyInterfaceController.cs (or whatever name you like) in the watch app extension project (NOT the watch app itself where the storyboard is). 添加下面的代码(更新命名空间、classname 和构造函数名称):Add the following code (updating the namespace, classname, and the constructor name):

    using System;
    using WatchKit;
    using Foundation;
    
    namespace WatchAppExtension  // remember to update this
    {
        public partial class MyInterfaceController // remember to update this
        : WKInterfaceController
        {
            public MyInterfaceController // remember to update this
            (IntPtr handle) : base (handle)
            {
            }
            public override void Awake (NSObject context)
            {
                base.Awake (context);
                // Configure interface objects here.
                Console.WriteLine ("{0} awake with context", this);
            }
            public override void WillActivate ()
            {
                // This method is called when the watch view controller is about to be visible to the user.
                Console.WriteLine ("{0} will activate", this);
            }
            public override void DidDeactivate ()
            {
                // This method is called when the watch view controller is no longer visible to the user.
                Console.WriteLine ("{0} did deactivate", this);
            }
        }
    }
    
  5. 在 " C# 监视应用扩展" 项目中创建另一个新文件MyInterfaceController.designer.cs ,并添加以下代码。Create another new C# file MyInterfaceController.designer.cs in the watch app extension project and add the code below. 请确保更新命名空间、classname 和 Register 属性:Be sure to update the namespace, the classname and the Register attribute:

    using Foundation;
    using System.CodeDom.Compiler;
    
    namespace HelloWatchExtension  // remember to update this
    {
        [Register ("MyInterfaceController")] // remember to update this
        partial class MyInterfaceController  // remember to update this
        {
            void ReleaseDesignerOutlets ()
            {
            }
        }
    }
    

    提示

    您可以选择将此文件作为第一个文件的子节点,方法是将其拖到 Visual Studio for Mac C# Solution Pad 的其他文件中。You can (optionally) make this file a child node of the first file by dragging it onto the other C# file in the Visual Studio for Mac Solution Pad. 它将如下所示:It will then appear like this:

  6. 选择 "生成" > "生成所有",以便 Xcode 同步将识别使用的新类(通过 Register 属性)。Select Build > Build All so that Xcode synchronization will recognize the new class (via the Register attribute) that we used.

  7. 右键单击 "监视应用情节提要" 文件并选择 "打开方式" > Xcode "Interface Builder,重新打开情节提要:Re-open the storyboard by right-clicking on the watch app storyboard file and selecting Open With > Xcode Interface Builder:

  8. 选择新的接口控制器,并为其指定上面定义的类名,例如。Select your new interface controller and give it the classname you defined above, eg. MyInterfaceControllerMyInterfaceController. 如果一切都正常工作,则它应自动显示在类: 下拉列表中,你可以从该下拉列表中选择它。If everything has worked correctly, it should appear automatically in the Class: drop down list and you can select it from there.

  9. 选择 Xcode 中的 "助手编辑器" 视图(具有两个重叠圆圈的图标),以便您可以并排查看情节提要和代码:Choose the Assistant Editor view in Xcode (the icon with two overlapping circles) so that you can see the storyboard and the code side-by-side:

    当焦点位于 "代码" 窗格中时,请确保查看的是 .h头文件,如果不在痕迹导航栏中右键单击并选择正确的文件(MyInterfaceControllerWhen the focus is in the code pane, ensure you're look at the .h header file, and if not right-click in the breadcrumb bar and select the correct file (MyInterfaceController.h)

  10. 你现在可以通过Ctrl + 从情节提要拖到 .h头文件来创建输出口和操作。You can now create outlets and actions by Ctrl + drag from the storyboard into the .h header file.

    当你放开拖动时,系统将提示你选择是创建输出口还是使用操作,并选择其名称:When you release the drag, you'll be prompted to select whether to create an outlet or an action, and choose its name:

  11. 保存情节提要更改并关闭 Xcode 后,将返回 Visual Studio for Mac。Once the storyboard changes are saved and Xcode is closed, return to Visual Studio for Mac. 它将检测头文件更改,并自动将代码添加到designer.cs文件中:It will detect the header file changes and automatically add code to the .designer.cs file:

    [Register ("MyInterfaceController")]
    partial class MyInterfaceController
    {
        [Outlet]
        WatchKit.WKInterfaceButton myButton { get; set; }
    
        void ReleaseDesignerOutlets ()
        {
            if (myButton != null) {
                myButton.Dispose ();
                myButton = null;
            }
        }
    }
    

你现在可以在中C#引用控件(或实现操作)!You can now reference the control (or implement the action) in C#!

从命令行启动 Watch 应用Launching the Watch App from the Command Line

重要

默认情况下,你可以在普通应用模式下启动 "监视应用",也可以使用 Visual Studio for Mac 和 Visual Studio 中的自定义执行参数一目了然通知模式。You can start the Watch App in normal app mode by default, and also in Glance or Notification modes using custom execution parameters in Visual Studio for Mac and Visual Studio.

你还可以使用命令行来控制 iOS 模拟器。You can also use the command line to control the iOS Simulator. 用于启动监视应用的命令行工具是mtouchThe command line tool used to launch watch apps is mtouch.

下面是一个完整示例(在终端中作为单行执行):Here is a full example (executed as a single line in the terminal):

/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch --sdkroot=/Applications/Xcode.app/Contents/Developer/ --device=:v2:runtime=com.apple.CoreSimulator.SimRuntime.iOS-8-2,devicetype=com.apple.CoreSimulator.SimDeviceType.iPhone-6
--launchsimwatch=/path/to/watchkitproject/watchsample/bin/iPhoneSimulator/Debug/watchsample.app

需要更新以反映应用 launchsimwatch的参数:The parameter you need to update to reflect your app is launchsimwatch:

--launchsimwatch--launchsimwatch

适用于 iOS 应用的主应用捆绑包的完整路径 ,其中包含 watch 应用和扩展The full path to the main app bundle for the iOS app that contains the watch app and extension.

备注

你需要提供的路径适用于iPhone 应用程序应用程序文件,即,将部署到 iOS 模拟器并包含监视扩展和监视应用的路径。The path you need to supply is for the iPhone application .app file, i.e. the one that will be deployed to the iOS simulator and that contains both the watch extension and watch app.

示例:Example:

--launchsimwatch=/path/to/watchkitproject/watchsample/bin/iPhoneSimulator/Debug/watchsample.app

通知模式Notification Mode

若要测试应用的通知模式,请将 watchlaunchmode 参数设置为 Notification,并提供包含测试通知负载的 JSON 文件的路径。To test the app's Notification mode, set the watchlaunchmode parameter to Notification and supply a path to a JSON file that contains a test notification payload.

负载参数对于通知模式是必需的。The payload parameter is required for Notification mode.

例如,将以下参数添加到 mtouch 命令:For example, add these arguments to the mtouch command:

--watchlaunchmode=Notification --watchnotificationpayload=/path/to/file.json

其他参数Other Arguments

其余参数如下所述:The remaining arguments are explained below:

--sdkroot--sdkroot

必须的。Required. 指定 Xcode (6.2 或更高版本)的路径。Specifies the path to Xcode (6.2 or later).

示例:Example:

 --sdkroot /Applications/Xcode.app/Contents/Developer/

--设备--device

要执行的模拟器设备。The simulator device to execute. 这可以通过两种方式来指定:使用特定设备的 udid 或使用运行时和设备类型的组合。This can be specified in two ways, either using the udid of a specific device, or using a combination of runtime and device type.

确切的值因计算机而异,可使用 Apple 的simctl工具进行查询:The exact values varies between machines, and can be queried using Apple’s simctl tool:

/Applications/Xcode.app/Contents/Developer/usr/bin/simctl list

UDIDUDID

示例:Example:

--device=:v2:udid=AAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE

运行时和设备类型Runtime and Device type

示例:Example:

--device=:v2:runtime=com.apple.CoreSimulator.SimRuntime.iOS-8-2,devicetype=com.apple.CoreSimulator.SimDeviceType.iPhone-6