将Firebase参考发送到Apple Watch [英] Sending Firebase reference to Apple Watch

查看:51
本文介绍了将Firebase参考发送到Apple Watch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我的处境有点复杂,但是基本上我有一个Apple Watch扩展程序与我的应用程序连接,该扩展程序使用Firebase来接收和发送数据.我希望手表与应用程序具有相同的功能,唯一的问题是我需要使用相同的Firebase参考,因为我使用的是Google身份验证,并且需要保持auth数据不变(除非有其他方法).因此,我所监视的工作是最初请求一些数据:所选计时器的索引(这是一个计时器应用程序)和Firebase参考变量.但是,当iPhone应用程序使用reply()函数并发送回字典时,如下所示:

Alright so my situation here is a little complicated, but basically I have a an Apple Watch extension connected with my app, which uses Firebase to receive and send data. I want the same functionality in my watch as I do the app, the only problem is that I need to use the same Firebase reference because I use Google Authentication and I need to keep the auth data the same (unless there is another way). So what I have the watch do is request some data initially: the index of the selected timer (it's a timer app) and the Firebase reference variable. But when the iPhone app uses the reply() function and sends back a dictionary like so:

reply(["replyInfoType": "watchInfo", "selectedTimerKey": keySelected, "refFirebase": ref])

ref 变量定义为 var ref = Firebase(url:"https://my-app-url.firebaseio.com/").编译没有错误,但是当我运行watch扩展并附加到应用程序进程时,我的应用程序在此处抛出一个不错的SIGABRT:日志中什么都没有打印.在我取消暂停过程后,该应用程序便崩溃了.我没有线索这是从哪里来的.如果我在字典中不包含 ref 变量,则其运行正常,除了我的手表应用无权读取Firebase数据库的事实.

The ref variable is defined as var ref = Firebase(url:"https://my-app-url.firebaseio.com/"). There are no errors compiling but when I run the watch extension and attach to the application process as well, my application throws a nice SIGABRT here: Nothing is printed in the log at all. The app just crashes after I unpause the process. I have no leads on where this is coming from. If I don't include the ref variable in the dictionary it runs fine except for the fact that my watch app doesn't have permission to read the Firebase Database.

推荐答案

通过 handleWatchKitRequest 方法在手表和iOS设备之间移动的所有数据都必须可序列化.

All datas moving between your watch and your iOS device through handleWatchKitRequest method must be serializable.

您可能可以尝试在Firebase对象上使用NSKeyedArchiver来确定它是否可序列化.

You can probably try to use NSKeyedArchiver on your Firebase object to find out if it's serializable or not.

您是否尝试过将Firebase参考的链接作为字符串返回,然后在Watch上实例化Firebase对象?(不过,这可能不是在iOS和Watch应用中监听Firebase节点的最佳解决方案)

Have you tried returning the link of your Firebase reference as a string and then instantiate a Firebase object on the Watch? (might not be the best solution to listen on firebase nodes in both your iOS and Watch app, though)

此外,我建议您看看NSUserDefaults和共享容器,这可能是实现您想要做的一个很好的方法,这里是链接:

Also, I suggest you to have a look at NSUserDefaults and shared containers, might be a good way to achieve what you want to do, here is the link : https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/WatchKitProgrammingGuide/DesigningaWatchKitApp.html#//apple_ref/doc/uid/TP40014969-CH3-SW4

这篇关于将Firebase参考发送到Apple Watch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆