问题描述
我想知道我的用户是否有 Apple Watch.如果有很多用户这样做,那么我将为我的 iOS 应用程序开发 Apple Watch 应用程序扩展.我能知道连手表都没有配对吗?
I want to know if my users have Apple Watch. If many user do, so I will develop Apple Watch application extension for my iOS app. Can I know if even watch is not paired?
推荐答案
你应该看看 WatchConnectivity 框架.特别是,WCSession
的 isPaired 方法应该可以解决您的问题.
You should look at the WatchConnectivity framework. Especially, the isPaired method of WCSession
should solve your problem.
在您的 iPhone 应用程序的 application(didFinishLaunchingWithOptions:)
方法中,设置并激活 WatchConnectivity 会话,因为 isPaired
仅返回激活会话的有效值.>
In your iPhone app's application(didFinishLaunchingWithOptions:)
method, set up and activate the WatchConnectivity session, since isPaired
only returns a valid value for an activated session.
//Set up WatchConnectivity
if WCSession.isSupported() {
let session = WCSession.default()
session.delegate = self
session.activate()
}
在 func session(activationDidCompleteWith)
中,您可以使用以下代码行检查 iPhone 是否与 Apple Watch 配对:让 userHasAppleWatch = session.isPaired
.
In func session(activationDidCompleteWith)
you can check if the iPhone is paired with an Apple Watch or not using this line of code:let userHasAppleWatch = session.isPaired
.
这篇关于如果用户拥有没有手表扩展程序的 Apple Watch,如何在 iOS 应用程序中进行跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!