Apple Watch 设备上的测试Testing on Apple Watch Devices

完成创建应用程序 Id 和应用程序组所需的部署步骤后(如果需要),请使用此页上的说明执行以下操作:After you've followed the deployment steps to create App IDs and App Groups (if required), use the instructions on this page to:

设备Devices

在实际 iPhone 或 iPad 上测试 iOS 应用始终需要在开发人员中心注册设备。Testing iOS apps on a real iPhone or iPad has always required the device to be registered on the Dev Center. 设备列表如下所示(单击加号 + 以添加新设备):The device list looks like this (click the plus sign + to add a new device):

监视没有什么不同-你现在需要在将应用部署到 Apple Watch 设备之前添加它。Watches are no different - you now need to add your Apple Watch device before deploying apps to it. 使用Xcode查找监视的 UDID (Windows > 设备列表)。Find the watch's UDID using Xcode (Windows > Devices list). 当配对电话连接时,还会显示该手表的信息:When the paired phone is connected the watch's information will also be displayed:

知道手表的 UDID 后,将其添加到开发人员中心内的设备列表:When you know the Watch's UDID, add it to the device list in the Dev Center:

添加监视设备后,请确保在创建的任何新的或现有的开发或即席预配配置文件中选择该设备:Once the Watch device has been added, ensure it is selected in any new or existing development or ad-hoc provisioning profiles you create:

别忘了编辑现有的预配配置文件以进行下载并重新安装!Don't forget if you edit an existing provisioning profile to download and re-install it!

开发预配配置文件Development Provisioning Profiles

若要在设备上进行测试,需要在解决方案中为每个应用 ID 创建一个开发预配配置文件To build for testing on your device you need to create a Development Provisioning Profile for each App ID in your solution.

如果你有通配符应用 ID,则只需要一个配置文件;但是,如果每个项目都有单独的应用 ID,则每个应用 ID 都需要一个预配配置文件:If you have a wildcard App ID, only one Provisioning Profile will be required; but if you have a separate App ID for each project then you'll need a provisioning profile for each App ID:

创建所有三个配置文件后,它们将显示在列表中。Once you've created all three profiles, they'll appear in the list. 请记住下载并安装每个:Remember to download and install each one:

可以通过选择 "生成" > "IOS 捆绑签名" 屏幕,然后选择 "发布" 或 "调试 iPhone " 配置来验证 "项目选项" 中的预配配置文件。You can verify the provisioning profile in the Project Options by selecting the Build > iOS Bundle Signing screen and selecting the Release or Debug iPhone configuration.

"预配配置文件" 列表将显示所有匹配的配置文件,你应在此下拉列表中看到已创建的匹配配置文件:The Provisioning Profile list will show all matching profiles - you should see the matching profiles that you've created in this drop-down list:

监视设备上的测试Testing on a Watch device

配置好设备、应用程序 Id 和预配配置文件后,即可进行测试。Once you have configured your Device, App IDs, and Provisioning Profiles, you are ready to test.

  1. 请确保已插入 iPhone,并已将手表与 iPhone 配对。Make sure your iPhone is plugged in, and the Watch is already paired with the iPhone.

  2. 确保配置设置为 "发布" 或 "调试"。Ensure the configuration is set to Release or Debug.

  3. 确保在 "目标" 列表中选择了 "连接的 iPhone 设备"。Ensure the connected iPhone device is selected in the target list.

  4. 右键单击 iOS 应用程序项目(不是 "监视" 或 "扩展"),然后选择 "设为启动项目"。Right-click on the iOS App project (not the watch or extension) and choose Set As Startup Project.

  5. 单击 "运行" 按钮(或从 "运行" 菜单中选择 "启动" 选项)。Click the Run button (or choose a Start option from the Run menu).

  6. 解决方案将生成,iOS 应用将部署到 iPhone。The solution will build and the iOS app will be deployed to the iPhone. 如果未正确设置 iOS 应用或监视扩展预配,则部署到 iPhone 将会失败。If the iOS app or watch extension provisioning is not set correctly then deployment to the iPhone will fail.

  7. 如果部署成功完成,iPhone 会自动尝试将监视应用发送到配对的监视。If deployment completes successfully, the iPhone will automatically attempt to send the watch app to the paired Watch. 应用图标将显示在 "监视" 屏幕上,其中显示 "循环安装进度指示器"。Your app icon will appear on the watch screen with a circular installing progress indicator.

  8. 如果成功安装了 "监视" 应用,则图标将保留在 "监视" 屏幕上-触控它,开始测试应用!If the watch app is successfully installed, the icon will remain on the watch screen - touch it to start testing your app!

疑难解答Troubleshooting

如果在部署过程中出现错误,请使用视图 > pad > 设备日志查看有关错误的详细信息。If an error occurs during deployment use the View > Pads > Device Log to see more information about the error. 下面列出了一些错误及其原因:Some errors and their causes are listed below:

错误 MT3001:无法对程序集进行 AOT 操作Error MT3001: Could not AOT the assembly

在调试模式下生成以部署到 Apple Watch 设备时,可能会出现这种情况。This may occur when building in DEBUG mode to deploy to an Apple Watch device.

若要暂时解决此问题,请在 "监视扩展项目选项" > 生成 > watchOS 生成"窗口中禁用增量生成To temporarily work around this issue, disable Incremental Builds in the Watch Extension Project Options > Build > watchOS Build window:

这将在将来的版本中得到修复,之后,可以重新启用增量生成以利用更快的生成时间。This will be fixed in a future release, after which incremental builds can be re-enabled to take advantage of faster build times.

在设备上进行调试时,无法启动监视应用Watch App fails to start while debugging on device

尝试在物理设备上调试监视应用时,仅显示 & 加载 "微调框的图标(最终超时)。When attempting to debug a watch app on a physical device, only the icon & loading spinner appear (and eventually time-out). 此问题将在将来的版本中得到解决;解决方法是运行发布版本(将不允许调试)。This will be addressed in a future release; a workaround is to run a RELEASE build (which will not allow debugging).

应用程序可执行文件无效,或者应用程序验证失败Invalid Application Executable or Application Verification Failed

Failed to install [APPNAME]
Invalid executable/Application Verification Failed

如果在应用尝试安装后这些消息出现在 "监视" 屏幕上,可能会出现以下几个问题:If these messages appear on the watch screen after the app has attempted to install, there could be a couple of issues:

  • 在 Apple 开发人员中心,未将监视设备本身添加为设备。The Watch device itself has not been added as a device on the Apple Dev Center. 按照说明正确配置设备Follow the instructions to configure devices correctly.

  • 用于测试的开发预配配置文件未包含监视设备;或者,在将手表添加到预配配置文件后,不会重新下载并重新安装它们。The development provisioning profiles being used for testing did not have the Watch device included; or after the Watch was added to the provisioning profiles they weren't re-downloaded and re-installed. 按照说明正确配置预配配置文件Follow the instructions to configure the provisioning profiles correctly.

  • 如果IOS 设备日志包含 The system version is lower than the minimum OS version specified for bundle...Have 8.2; need 8.3 则 Watch 应用的info.plist具有错误的MinimumOSVersion值。If the iOS Device Log contains The system version is lower than the minimum OS version specified for bundle...Have 8.2; need 8.3 then the Watch App's Info.plist has the wrong MinimumOSVersion value. 这应该是8.2 -如果你已安装 Xcode 6.3,你可能需要手动编辑要插入的源,并将其设置为8.2。This should be 8.2 - if you have installed Xcode 6.3 you might need to manually edit the source to insert set it to 8.2.

  • 手表应用的info.plist不正确地启用了权利(如应用组)。The Watch App's Entitlements.plist incorrectly has an entitlement enabled (such as App Groups) that it shouldn't have.

  • 监视应用的应用 ID不正确地在开发人员中心中启用了授权(如应用组)。The Watch App's App ID incorrectly has an entitlement enabled (such as App Groups) in the Dev Center that it shouldn't have.

安装从未完成Install Never Finished

SPErrorGizmoInstallNeverFinishedErrorMessage

此错误可能表示 Watch 应用的info.plist文件中的键不必要(和无效)。This error could indicate unnecessary (and invalid) keys in the Watch App's Info.plist file. 不应在 Watch 应用中包含用于 iOS 应用或监视扩展的键。You should not include keys meant for the iOS app or watch extension in the Watch App.

"等待调试器连接""waiting for debugger to connect"

如果 "应用程序输出" 窗口显示停滞If the Application Output window gets stuck showing

waiting for debugger to connect

检查项目中包含的任何 Nuget 是否依赖于 ""。check if any of the NuGets that have been included in your project have a dependency on Microsoft.Bcl.Build. 这会自动添加到一些 Microsoft 发布的库,其中包括流行的Microsoft Http 客户端库This is automatically added with some Microsoft-published libraries including the popular Microsoft Http Client Libraries.

添加到 .csproj 的Microsoft. .csproj文件会在部署过程中干扰 iOS 扩展的打包。The Microsoft.Bcl.Build.targets file that is added to the .csproj can interfere with the packaging of iOS extensions during deployment. 您可以跟踪bugYou can track the bug. 一种可能的解决方法是编辑 .csproj 文件,并手动将它们移到最后一个元素。A possible workaround is to edit the .csproj file and manually move the Microsoft.Bcl.Build.targets to be the last element.