firebase-ios-sdk icon indicating copy to clipboard operation
firebase-ios-sdk copied to clipboard

SwiftRX FirebaseDatabase snapshot <null> when handling launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification]

Open mattRiddoch opened this issue 9 years ago • 4 comments

[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()
    }
}

mattRiddoch avatar Sep 17 '17 18:09 mattRiddoch

I have the same issue. Is there a way to solve it already?

avdgriendt avatar Jul 03 '18 06:07 avdgriendt

I'm wondering if you're still encountering this issue using the latest SDK version? If so, it would be great if you could provide a minimal repro to reproduce the issue.

rizafran avatar Oct 17 '19 14:10 rizafran

Hey @mattRiddoch. We need more information to resolve this issue but there hasn't been an update in 7 days. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot avatar Oct 25 '19 01:10 google-oss-bot

Since there haven't been any recent updates here, I am going to close this issue.

@mattRiddoch if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

google-oss-bot avatar Oct 29 '19 01:10 google-oss-bot