0

enter image description here enter image description here

I have tried every possible solutions for above issue but still not getting notification to my device via Firebase Console. Please suggest.

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()
}

Few firebase warnings are also displaying in the debugger:

KENdi
  • 7,576
  • 2
  • 16
  • 31
Ruhi
  • 176
  • 2
  • 16

3 Answers3

0

Please make sure you have enabled push notification capabilities from project target capabilities section shown in the picture if you are deploying the application from Xcode 8 or later. enter image description here

Nishant Bhindi
  • 2,242
  • 8
  • 21
0

I think the problem is because of the ios version. ios 10 requires UNUserNotificationCenter. Try the code below and add the function to your application 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()
    }
}
Sherman
  • 171
  • 7
  • Not sure if you have done this but you need to go to firebase project settings, choose cloud messaging and upload APNs development certificate for development stage in order to receive firebase notification. You also need a real device in order to receive notification. Unable to do notification testing on simulators. – Sherman May 24 '17 at 04:58
0

enter image description hereIssue Resolved for me. I skipped uploading APNs development certificate. enter image description here

Ruhi
  • 176
  • 2
  • 16