ios – 接收Push Notification时的Firebase没有收到弹出窗口

import Firebase
import FirebaseInstanceID
import FirebaseMessaging
func application(application: UIApplication,didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    registerForPushNotifications(application)
    FIRApp.configure()

    // Add observer for InstanceID token refresh callback.
    NSNotificationCenter
     .defaultCenter()
     .addobserver(self,selector: #selector(AppDelegate.tokenRefreshNotificaiton),name: kFIRInstanceIDTokenRefreshNotification,object: nil)

    // Override point for customization after application launch.
    return true
  }

func registerForPushNotifications(application: UIApplication) {
      let settings: UIUserNotificationSettings =
        UIUserNotificationSettings(forTypes: [.Alert,.Badge,.sound],categories: nil)
      application.registerUserNotificationSettings(settings)
      application.registerForRemoteNotifications()
  }


  func application(application: UIApplication,didReceiveRemoteNotification userInfo: [NSObject : AnyObject],fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
    print("===== didReceiveRemoteNotification ===== %@",userInfo)
  }


 func tokenRefreshNotificaiton(notification: NSNotification) {
    let refreshedToken = FIRInstanceID.instanceID().token()!
    print("InstanceID token: \(refreshedToken)")

    // Connect to FCM since connection may have Failed when attempted before having a token.
     connectToFcm()
  }

  func connectToFcm() {
    FIRMessaging.messaging().connectWithCompletion { (error) in
      if (error != nil) {
        print("Unable to connect with FCM. \(error)")
      } else {
        print("Connected to FCM.")
      }
    }
  }

还要在Info.plist中完成FirebaseAppDelegateProxyEnabled = NO

我现在不知道,但是我在didReceiveRemoteNotification中打印了(…),但是没有弹出.我从Firebase发送消息 – >控制台 – >通知 – >单个设备,并复制我从xCode控制台获取的令牌 – > func tokenRefreshNotificaiton

获取一个在控制台,但不要弹出

<FIRAnalytics/INFO> Firebase Analytics enabled
InstanceID token: TOKEN_ID
Connected to FCM.
===== didReceiveRemoteNotification ===== %@ [notification: {
    body = test;
    e = 1;
},collapse_key: com.pf.app,from: 178653764278]

还应用程序配置

解决方法

在AppDelegate.m中设置以下代码
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDevicetoken:(NSData *)devicetoken {

    // for development 
        [[FIRInstanceID instanceID] setAPNSToken:devicetoken type:FIRInstanceIDAPNSTokenTypeSandBox];

    // for production 
   //     [[FIRInstanceID instanceID] setAPNSToken:devicetoken type:FIRInstanceIDAPNSTokenTypeProd];


    }

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...