Firebase推送通知xcode控制台收到通知但在设备中它不工作ios目标c

时间:2017-03-30 13:03:22

标签: ios objective-c xcode

我正在使用firebase进行PushNotification但是有问题。通知是在设备中未收到的xcode控制台中收到的。我正在做一切正确但没有成功在设备中收到通知

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

1 个答案:

答案 0 :(得分:0)

您是在物理,真实设备上还是在模拟器上进行测试?在iOS模拟器上,您无法注册和接收推送通知:)

如果您正在使用真实设备而非模拟器,请提醒您调用以下功能以注册推送。     application.registerUserNotificationSettings(...)

致电之前: https://developer.apple.com/reference/uikit/uiapplication/1623078-registerforremotenotifications

总而言之:

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

一些有用的调试输出也可能是:

{{1}}