对象存在于firebase上。根据对象ID打开详细视图。 当应用程序背景并且从
调用该函数时,它工作正常func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void)
当应用程序被杀死并且处理通知时,快照返回null。
App Delegate:
AppName.shared.user.shareReplayLatestWhileConnected().filterNil().distinctUntilChanged({ lhs, rhs in
return lhs.key == rhs.key
}).subscribe() { event in
switch event {
case .next(let user):
self.userIdString = user.key
...
if let notificationInfo = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? [AnyHashable: Any] {
self.handleMessageFromRemoteNotification(notificationInfo)
}
}...
处理程序:
Event.load(url.lastPathComponent).single().subscribe(onNext: { event in
//prepare and present view here...
}).addDisposableTo(disposeBag)
事件加载失败功能:
static func load(_ id: String) -> Observable<Event> {
return Observable.create() { observer in
FirebaseDatabase.sharedInstance.ref.child("events/\(id)").observeSingleEvent(of: .value, with: {
snapshot in
//This the null snapshot
if snapshot.exists() {
if let event = Event(snapshot: snapshot) {
observer.onNext(event)
}
observer.on(.completed)
} else {
observer.on(.completed)
}
})
return Disposables.create()
}
}
答案 0 :(得分:0)
目前
FirebaseDatabase.sharedInstance.ref.child("events/\(id)").observe(.value
与
相反FirebaseDatabase.sharedInstance.ref.child("events/\(id)").observeSingleEvent(of: .value
似乎要解决它,会发表更多评论。