本文介绍了如果用户使用不带手表扩展功能的Apple Watch,如何在iOS应用中进行跟踪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我的用户是否有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应用中进行跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 21:27