You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SwiftUI自定义App中打开iPhone Watch App的正确URL咨询

打开iPhone上Watch应用的正确URL方案

itms-watch:// 这个URL scheme的作用是跳转至App Store的Watch应用下载页面,并非打开已安装在iPhone上的Watch应用。要直接打开iPhone本地的Watch应用,你需要使用**com.apple.Bridge://**这个官方URL scheme——Watch应用的内部bundle ID就是com.apple.Bridge。

修改后的代码实现

Button("Open Watch App") {
    if let url = URL(string: "com.apple.Bridge://") {
        if UIApplication.shared.canOpenURL(url) {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        } else {
            print("Watch app is not installed.")
        }
    }
}

iOS 9+ 关键配置要求

由于iOS 9及以上版本限制了未声明的URL scheme查询,你需要在项目的Info.plist文件中添加LSApplicationQueriesSchemes数组,并将com.apple.Bridge加入其中,否则canOpenURL(_:)会始终返回false:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>com.apple.Bridge</string>
</array>

内容的提问来源于stack exchange,提问作者Taimoor Arif

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 18:22:04