简体   繁体   中英

Firebase works fine on ios simulator but it does't work on real device

I am going to implement push notification using firebase on my ios app and I am using swift 3.1 as my programming language. I have implemented firebase on my app .It works fine on ios simulator and gives fcm token but on real device it does't work and does't give fcm token. any help?

I ran into this a while ago and this helped me from Ray Wenderlich . There are three core things you need to to be able to do push notifications on device:

  1. The app must be configured properly and registered with the Apple Push Notification Service (APNS) to receive push notifications upon every start-up.
  2. A server must send a push notification to APNS directed to one or more specific devices.
  3. The app must receive the push notification; it can then perform tasks or handle user actions using callbacks in the application delegate.

Might be late but here are my 2 cents.

I faced the same issue a few days back.

So basically the fix was that there was a delay required till you request your FCM token so that all the Firebase Libraries are initialised properly.

So something like this I coded in Xamarin iOS Project in my AppDelegate.cs, where you add a 2 sec delay to fetch the FCM token for the first time the user installs the app.

 var firstLoad = NSUserDefaults.StandardUserDefaults.StringForKey("isFirstLoad");

        if(firstLoad == null)
        {
            Thread.Sleep(2000);
            NSUserDefaults.StandardUserDefaults.SetString(false, "isFirstLoad");
        }

It works on Simulator because of high RAM and Processor but in real device it needs some extra time and in my case I was using Analytics, Crashlytics and Messaging.

Also make sure to check Console logs for proper error messages while running on device. If the FIRInstance is properly initialised the FCM token will come in the below delegate method.

optional func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM