将Firebase与WatchKit一起使用 [英] Using firebase with WatchKit
问题描述
我正在尝试在我的watchKit应用中使用firebase数据库.我已经在我的iPhone应用程序上开发了此功能,但是发现在我的Watch应用程序上很难做到这一点.当我尝试将firebase导入watch应用程序的VC类中时,它正在创建错误no such module 'firebase'
.
I am attempting to use the firebase database in my watchKit app. I have developed this feature on my iPhone application but have found it difficult to do the same on my Watch app. When I attempted to import firebase into the VC class in watch app, it is creating an error no such module 'firebase'
.
是否可以在手表应用程序内使用Firebase?
Is it possible to use firebase inside a watch app?
推荐答案
由于这些版本的watchOS
和Firebase
高度依赖于此框架. 来源(感谢评论中的@FrankvanPuffelen链接).
Sadly there is no Firebase
support for watchOS2
and watchOS3
due to the fact that there's no support for CFNetwork
in these versions of watchOS
and Firebase
is highly dependent on this framework. Source (thanks for the link @FrankvanPuffelen in comments).
您有两种选择:
- 直接在手表应用中使用
Firebase REST API
. - 处理来自
iPhone
应用程序的所有Firebase
通信,并使用WatchConnectivity
框架将相关更改发送到您的手表应用程序.
- Use the
Firebase REST API
directly from your watch app. - Handle all
Firebase
communication from theiPhone
app and use theWatchConnectivity
framework to send the relevant changes to your watch app.
根据您的确切用例,您可以选择两者之一.这两个主要的优点/缺点是WatchConnectivity
框架在使用时受到很大的限制.为了使WatchConenctivity
框架正常工作,您的两个应用都必须至少在后台运行.另一方面,如果选择使用REST API
,则不需要watch应用程序与iPhone
对方通信,watch应用程序可以使用网络请求直接获取Firebase
数据.但是,在这种情况下,网络使用量会更大,因为您实际上需要同时获取iPhone
和观看应用程序的相同信息.
Depending on your exact use case, you could choose any of the two. The main advantages/disadvantages of these two are that the WatchConnectivity
framework is quite limited as in when it can be used. Both of your apps needs to be running at least in the background for the WatchConenctivity
framework to work. On the other hand, if you choose to use the REST API
, you don't need the watch app to communicate with the iPhone
counterpart, the watch app can directly get the Firebase
data using network requests. However, in this scenario, the network usage will be bigger, since you will need to essentially fetch the same information both for the iPhone
and watch apps.
watchOS 6的更新: Firebase Messaging已发布,并具有watchOS支持,但是仍不支持Realtime Database和其他Firebase SDK.您可以在此 GitHub问题中跟踪它们的进度包含指向其他SDK的特定功能请求问题的链接.
Update for watchOS 6: Firebase Messaging has been released with watchOS support, however, the Realtime Database along with other Firebase SDKs are still not supported. You can track the progress of them in this GitHub issue, which also contains links to the specific feature request issues for the other SDKs.
这篇关于将Firebase与WatchKit一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!