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

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

问题描述

好吧,我这里的情况有点复杂,但基本上我有一个与我的应用程序连接的 Apple Watch 扩展程序,它使用 Firebase 来接收和发送数据.我希望在我的手表中使用与应用程序相同的功能,唯一的问题是我需要使用相同的 Firebase 参考,因为我使用 Google 身份验证并且我需要保持身份验证数据相同(除非有另一种方式).所以我让手表做的是最初请求一些数据:所选计时器的索引(它是一个计时器应用程序)和 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 和共享容器,这可能是实现你想要做的事情的好方法,这里是链接:https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/WatchKitProgrammingGuide/DesigningaWatchKitApp.html#//apple_ref/doc/uid/TP40014969-CH3-SW4

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

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

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