简体   繁体   中英

Firebase Push Notification xcode console received notification but in device it is not working ios Objective c

I am using firebase for PushNotification but there is problem. The notification is received in xcode console not received in device. I am doing everything right but no success to get notification in device

2017-03-31 16:40:44.265 [7188] <Warning> [Firebase/Analytics][I-ACS003016] Firebase Analytics App Delegate Proxy is disabled. To log deep link campaigns manually, call the methods in FIRAnalytics+AppDelegate.h.
2017-03-31 16:40:44.531 [7188] <Notice> [Firebase/Crash][I-CRA000004] Successfully initialized
2017-03-31 16:40:44.541: <FIRMessaging/INFO> FIRMessaging library version 1.2.2
2017-03-31 16:40:44.552 [7188:141393] *** -[NSKeyedUnarchiver initForReadingWithData:]: data is NULL
2017-03-31 16:40:44.666 [7188] <Notice> [Firebase/Analytics][I-ACS023007] Firebase Analytics v.3700000 started
2017-03-31 16:40:44.758 [7188] <Notice> [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled 
2017-03-31 16:40:45.124 [7188:141393] Unable to register for remote notifications: Error Domain=NSCocoaErrorDomain Code=3010 "REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTION" UserInfo={NSLocalizedDescription=REMOTE_NOTIFICATION_SIMULATOR_NOT_SUPPORTED_NSERROR_DESCRIPTION}
2017-03-31 16:40:45.816 [7188:141393] Connected to FCM.
2017-03-31 16:40:45.920 [7188] <Notice> [Firebase/Analytics][I-ACS023012] Firebase Analytics enabled

Do you test on a physical, real device or on the simulator? On iOS Simulator you cannot register and receive push notifications :)

If you are working a on a real device, not the simulator, be reminded to call the following functions to register for push. application.registerUserNotificationSettings(...)

Prior to the call: https://developer.apple.com/reference/uikit/uiapplication/1623078-registerforremotenotifications

So altogether:

if application.respondsToSelector("registerUserNotificationSettings:") {
        if #available(iOS 8.0, *) {
            let types:UIUserNotificationType = ([.Alert, .Sound, .Badge])
            let settings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: types, categories: nil)
            application.registerUserNotificationSettings(settings)
            application.registerForRemoteNotifications()
        } else {
            application.registerForRemoteNotificationTypes([.Alert, .Sound, .Badge])
        }
    }
    else {
        // Register for Push Notifications before iOS 8
        application.registerForRemoteNotificationTypes([.Alert, .Sound, .Badge])
    }

Some helpful debugging output could also be:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    let pushSettings = UIUserNotificationSettings(forTypes: [UIUserNotificationType.Badge ,UIUserNotificationType.Sound ,UIUserNotificationType.Alert], categories: nil)
    application.registerUserNotificationSettings(pushSettings)
    return true
}

func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
    application.registerForRemoteNotifications()
}

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
    let token=deviceToken.description
    print(token)
}

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
    print(error)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM