小编kun*_*aha的帖子

无法使用FCM在前台接收推送通知

我一直试图在我的应用程序中获取firebase推送通知.我已尝试过互联网上的所有内容但无法找到解决方案.我一直在后台收到通知,但是当App在前台时,我无法收到通知.但是当我在"didReceiveRemoteNotification"中打印userInfo时,我在控制台中收到消息.任何帮助都将不胜感激.

import Firebase
import UserNotifications


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate{

var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    //FirebaseApp.configure()

    self.initializeFCM(application)
    let token = InstanceID.instanceID().token()
    debugPrint("GCM TOKEN = \(String(describing: token))")

    return true
}

 func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error)
{
    debugPrint("didFailToRegisterForRemoteNotificationsWithError: \(error)")
}

func application(received remoteMessage: MessagingRemoteMessage)
{
    debugPrint("remoteMessage:\(remoteMessage.appData)")
}

func initializeFCM(_ application: UIApplication)
{
    print("initializeFCM")

    if #available(iOS 10.0, *) // enable new way for notifications on iOS 10
    {
        let center = UNUserNotificationCenter.current() …
Run Code Online (Sandbox Code Playgroud)

push-notification ios firebase swift firebase-cloud-messaging

0
推荐指数
1
解决办法
5050
查看次数