Moh*_*ani 21 ios apple-watch watchkit
有没有办法在Apple Watch中通知用户iPhone现在已经超出范围,何时返回范围.我们怎样才能在手表延伸中做到这一点.
提前致谢.
所以在WatchOS 2上这是可能的!
你必须在iPhone方面做:
第一:
import WatchConnectivity
Run Code Online (Sandbox Code Playgroud)
然后 :
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
}
}
Run Code Online (Sandbox Code Playgroud)
我希望它会帮助你:)
使用watchOS 2.0,你可以.要做到这一点,如果您希望Apple Watch获得通知,您可以将这些添加到您的ExtensionDelegate:
func watchKitSetup() {
if (WCSession.isSupported()) {
let session = WCSession.defaultSession()
session.delegate = self
session.activateSession()
// In your WatchKit extension, the value of this property is true when the paired iPhone is reachable via Bluetooth.
// On iOS, the value is true when the paired Apple Watch is reachable via Bluetooth and the associated Watch app is running in the foreground.
// In all other cases, the value is false.
if session.reachable {
}
}
}
func applicationDidFinishLaunching () {
self.watchKitSetup()
}
// Called when session.reachable value changes, such as when a user wearing an Apple Watch gets out of range of their iPhone.
func sessionReachabilityDidChange(session: WCSession) {
if session.reachable {
}
}
Run Code Online (Sandbox Code Playgroud)
您还应该将WCSessionDelegate添加到ExtensionDelegate.
从目前的知识来看,这可能是不可能的。
来自 Apple 的WatchKit 应用架构
选择场景后,WatchKit 会告诉配对的 iPhone 启动 WatchKit 扩展并创建管理该场景所需的对象。场景完全配置后,会显示在 Apple Watch 上。WatchKit 应用程序和 WatchKit 扩展之间的信息传输在幕后透明地进行。
这意味着,代码是在 iPhone 上执行的。如果 iPhone 超出范围,则无法在手表上运行该应用程序。
归档时间: |
|
查看次数: |
16490 次 |
最近记录: |