2017-09-16 161 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 

似乎解決它,將與更多的評論。