0
对象存在于firebase上。基于对象ID打开详细视图。 当应用程序在背景执行它工作正常,当应用程序被杀害的功能从RxSwift Firebase数据库快照<null>何时处理launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification]
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping() -> Void)
打来电话,通知处理快照回来空。
应用代表:
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()
}
}