简体   繁体   English

Firebase 在 ios 模拟器上运行良好,但在真实设备上不起作用

[英]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:要在设备上执行推送通知,您需要具备三个核心要素:

  1. The app must be configured properly and registered with the Apple Push Notification Service (APNS) to receive push notifications upon every start-up.应用程序必须正确配置并注册到 Apple 推送通知服务 (APNS) 才能在每次启动时接收推送通知。
  2. A server must send a push notification to APNS directed to one or more specific devices.服务器必须向 APNS 发送指向一个或多个特定设备的推送通知。
  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.可能会迟到,但这是我的 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.

相关问题 Xamarin.ios 不适用于真正的 iOS 设备,但它适用于模拟器 - Xamarin.ios does NOT work on real iOS device but it works on Simulator iOS App在Simulator上运行正常,但在真实的iOS设备上崩溃 - iOS App works fine with Simulator but Crashes with a real iOS device iOS应用程序不会在设备上编译,但在模拟器中工作正常 - iOS app won't compile on device but works fine in simulator IOS App在iTunes版本上崩溃,但在本地模拟器和真实设备测试中运行良好 - IOS App crashed on iTunes' version, but works fine on local simulator & real device testing iOS应用可在模拟器上运行,但不能在真实设备上运行 - iOS app works on simulator but not on real device Firebase与模拟器连接,但未在真实设备iOS中连接 - Firebase connecting with simulator but not in real device iOS LottieView 在 iOS 模拟器中工作,但在设备上不起作用 -- Expo - LottieView Works in iOS Simulator, but doesn't work on device -- Expo iOS模拟器崩溃而真实设备没有崩溃 - iOS Simulator crashes while real device does not 科尔多瓦:警报未在桌面环境中显示(它们在模拟器和真实设备上均能正常工作) - Cordova: Alerts not shown on desktop environment (They work fine on simulator and real device) 为什么FBSDKAccessToken.currentAccessToken()在我的设备上返回nil,但是在iOS模拟器中可以正常工作? - Why does FBSDKAccessToken.currentAccessToken() returns nil on my device but works fine in the iOS simulator?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM