ios - 如何检查 iPhone 和 Apple Watch 是否连接

标签 ios watchkit apple-watch

有什么方法可以在 Apple Watch 中通知用户 iPhone 现在超出范围以及何时返回范围内。我们如何在 watch 扩展中做到这一点。

提前致谢。

最佳答案

所以在 WatchOS 2 上这是可能的!

你必须在 iPhone 端做:

首先:

import WatchConnectivity

然后:

   if WCSession.isSupported() { // check if the device support to handle an Apple Watch
        let session = WCSession.defaultSession()
        session.delegate = self
        session.activateSession() // activate the session

        if session.paired { // Check if the iPhone is paired with the Apple Watch
                // Do stuff
        }
    }

希望对你有帮助:)

关于ios - 如何检查 iPhone 和 Apple Watch 是否连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27793093/

相关文章:

ios - 如何在 iOS 中查看已声明变量的描述

objective-c - 为 Watch OS2 创建扩展委托(delegate)类

ios - 如何响应 Apple Watch 的表冠滚动?

ios - Xcode 11.1 升级奇怪之处 - 主屏幕显示为模态视图

iphone - 更改界面方向时在 UIScrollView 上出现奇怪的跳转 (ATPagingView)

ios - 订阅位于 UITableViewDataSource 内的 UITableViewCell 中的 UIButton.rx.tap

ios - WatchKit 扩展包标识符

swift - 如何使用 Watch Connectivity 从 iPhone 发送的 [String] 数组填充表格行?

ios - WatchKit 扩展配置文件?

ios - 观看连接 session 问题