0

enter image description here enter image description here通知不是通过火力地堡控制台来

我已经尝试了上述问题,每一个可能的解决方案,但仍然没有得到通知,通过火力地堡控制台我的设备。请建议。

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
FIRApp.configure() 
if let remoteNotification = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary { 

     self.handleNotification(remoteNotification as! [NSObject : AnyObject]) 
    } 
    let settings: UIUserNotificationSettings = 
     UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil) 
    application.registerUserNotificationSettings(settings) 
    application.registerForRemoteNotifications() 

    // Add observer for InstanceID token refresh callback. 
    NSNotificationCenter 
     .defaultCenter() 
     .addObserver(self, selector: #selector(AppDelegate.tokenRefreshNotificaiton), 
        name: kFIRInstanceIDTokenRefreshNotification, object: nil) 
return true } 
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], 
       fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) { 


    FIRMessaging.messaging().appDidReceiveMessage(userInfo) 



    NSNotificationCenter.defaultCenter().postNotificationName("reloadTheTable", object: nil) 


} 

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { 

    FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Sandbox) 
} 
func tokenRefreshNotificaiton(notification: NSNotification) { 
    guard let refreshedToken = FIRInstanceID.instanceID().token() 
     else { 
      return 
    } 


    print("InstanceID token: \(refreshedToken)") 

    utill.tokenDefault.setValue(refreshedToken, forKey: "tokenId") 

    connectToFcm() 
} 

几个火力点的警告也显示在调试器:

回答

0

enter image description here问题已解决。 我跳过上传APNs开发证书。 enter image description here

0

请确保您已启用了从项目目标的能力一节,如果你在Xcode 8或更高版本的应用程序部署在画面中显示推送通知功能。 enter image description here

+0

推送通知已启用。 –

+0

上面的屏幕截图显示无法获取APNS令牌。请检查您是否收到设备令牌并已上传正确的p12证书。 –

0

我觉得问题是因为ios版本。 ios 10需要UNUserNotificationCenter。尝试下面的代码并将函数添加到应用程序didFinishLaunching中。

func registerForRemoteNotification() { 
    if #available(iOS 10.0, *) { 
     let center = UNUserNotificationCenter.current() 
     center.delegate = self 
     center.requestAuthorization(options: [.sound, .alert, .badge]) { (granted, error) in 
      if error == nil{ 
       UIApplication.shared.registerForRemoteNotifications() 
      } 
     } 
    } 
    else { 
     UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil)) 
     UIApplication.shared.registerForRemoteNotifications() 
    } 
} 
+0

不知道您是否已经完成了这项工作,但您需要转到Firebase项目设置,选择云消息传递并上传开发阶段的APN开发证书,以便接收Firebase通知。您还需要一个真实的设备才能收到通知。无法在模拟器上进行通知测试。 – Sherman