[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When app first launch instanceID token works fine, but some time later token becomes invalid #3005

Closed
kunwang opened this issue May 15, 2019 · 2 comments

Comments

@kunwang
Copy link
kunwang commented May 15, 2019

[READ] Step 1: Are you in the right place?

Yes

[REQUIRED] Step 2: Describe your environment

  • Xcode version: 10.2.1
  • Firebase SDK version: 5.20.2
  • Firebase Component: Messaging
  • Component version: 5.20.2

[REQUIRED] Step 3: Describe the problem

when app first launch, the firebase token works fine, close app and some time later, the token become invalid.When we send notification, we receive "NotRegistered" error.

Relevant Code:

   func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    FirebaseApp.configure()
    NotificationCenter.default.addObserver(self, selector: #selector(refreshToken), name: .MessagingRegistrationTokenRefreshed, object: nil)
    let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
    UNUserNotificationCenter.current().requestAuthorization(
        options: authOptions,
        completionHandler: {_, _ in })
   application.registerForRemoteNotifications()
    return true
}

  @objc
  public func refreshToken() {
        InstanceID.instanceID().instanceID(handler: {(result, error) in
            if let refreshedToken = result?.token {
                NotificationRequests.regFIRTokenAndDeviceID(refreshedToken)
            }
        })
    }

   public func setAPNSToken(_ deviceToken: Data) {
        Messaging.messaging().apnsToken = deviceToken
        refreshToken()
   }
@charlotteliang
Copy link
Contributor

Seems like a similar issue like #2438.

#2860
should fix the issue. which coming in the next release. Please try it out and reopen if this issue still occur to you.

@kunwang
Copy link
Author
kunwang commented May 16, 2019

@chliangGoogle Thanks

@firebase firebase locked and limited conversation to collaborators Oct 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants