Description
[READ] Step 1: Are you in the right place?
- For issues or feature requests related to the code in this repository
file a Github issue.- If this is a feature request make sure the issue title starts with "FR:".
- For general technical questions, post a question on StackOverflow
with the firebase tag. - For general Firebase discussion, use the firebase-talk
google group. - For help troubleshooting your application that does not fall under one
of the above categories, reach out to the personalized
Firebase support channel.
[REQUIRED] Step 2: Describe your environment
- Xcode version: 8.3.3
- Firebase SDK version: 4.1.1
- Library version: FirebaseMessaging (2.0.2) FirebaseDatabase (4.0.2)
- Firebase Product: FirebaseMessaging/FirebaseDatabase (auth, database, storage, core, messaging, etc)
[REQUIRED] Step 3: Describe the problem
As described in this SO issue: https://stackoverflow.com/questions/46250331/swiftrx-firebasedatabase-snapshot-null-when-handling-launchoptionsuiapplicat
When a push notification is handled in the app delegate from a killed state the call the the object referenced in the notification comes back null. The object exists on firebase. The handler works fine when a notification is received in backgrounded state. The app is initialized and user logged-in. AppDelegate is not using swizzling.
By introducing a 2 second delay prior to handling the payload from the appdelegate I am able to successfully load the object
Steps to reproduce:
- Edit scheme in xcode so that the 'Launch' property is set to 'Wait for executable to be launched'.
- Kill any running instance.
- Send notification to device.
- Fail??
What happened? How can we make the problem occur?
This could be a description, log/console output, etc.
console output: Snap (-KuG9HblEScjJEDqokS7)
Relevant Code:
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)
}
}...
URL handler:
Event.load(url.lastPathComponent).single().subscribe(onNext: { event in
//prepare and present view here...
}).addDisposableTo(disposeBag)
Failing code to load event:
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()
}
}