[英]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.我将在我的 ios 应用程序上使用 firebase 实现推送通知,并且我使用 swift 3.1 作为我的编程语言。 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.
我已经在我的应用程序上实现了 firebase。它在 ios 模拟器上运行良好并提供 fcm 令牌,但在真实设备上它不起作用并且不提供 fcm 令牌。 any help?
有什么帮助吗?
I ran into this a while ago and this helped me from Ray Wenderlich .不久前我遇到了这个问题,这从Ray Wenderlich 那里帮助了我。 There are three core things you need to to be able to do push notifications on device:
要在设备上执行推送通知,您需要具备三个核心要素:
Might be late but here are my 2 cents.可能会迟到,但这是我的 2 美分。
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.所以基本上解决方法是在您请求 FCM 令牌之前需要延迟,以便正确初始化所有 Firebase 库。
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.因此,我在 AppDelegate.cs 中的 Xamarin iOS 项目中编写了类似的代码,在其中添加 2 秒延迟以在用户第一次安装应用程序时获取 FCM 令牌。
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.由于 RAM 和处理器较高,它可以在模拟器上运行,但在实际设备中它需要一些额外的时间,就我而言,我使用的是 Analytics、Crashlytics 和 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.
如果 FIRInstance 正确初始化,则 FCM 令牌将出现在下面的委托方法中。
optional func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.