2017-09-16 160 views
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() 
    } 
} 

回答

0

眼下

FirebaseDatabase.sharedInstance.ref.child("events/\(id)").observe(.value 

与之相对

FirebaseDatabase.sharedInstance.ref.child("events/\(id)").observeSingleEvent(of: .value 

似乎解决它,将与更多的评论。