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