简体   繁体   English

无法为推送通知注册设备(iOS8)

[英]Cannot register device for push notifications (iOS8)

I am following the Parse tutorial to configure my device for push notifications. 我正在按照Parse教程配置我的设备以进行推送通知。

https://www.parse.com/tutorials/ios-push-notifications https://www.parse.com/tutorials/ios-push-notifications

My apple developer screen shows they are enabled: 我的苹果开发人员屏幕显示它们已启用:

在此输入图像描述

I have installed the push cert: 我已经安装了推送证书:

在此输入图像描述

I have added the .p12 cert to the settings sections on Parse: 我已经将.p12证书添加到了Parse的设置部分:

在此输入图像描述

I have added the requested code to my appdelegate: 我已将请求的代码添加到我的appdelegate中:

    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    PFPush.handlePush(userInfo)
}

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
    let installation = PFInstallation.currentInstallation()
    installation.setDeviceTokenFromData(deviceToken)
    installation.saveInBackground()
}

/** Get the availability to use the GPS at any given time */
func availabile() -> Bool {
    return !(locationServices.getGlobalManager().location == nil)
}

  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Override point for customization after application launch.
    Parse.setApplicationId("<redacted>",  clientKey:"<redacted>")


    let userNotificationTypes = (UIUserNotificationType.Alert |
        UIUserNotificationType.Badge |
        UIUserNotificationType.Sound);

    let settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
    application.registerUserNotificationSettings(settings)
    application.registerForRemoteNotifications()

    GMSServices.provideAPIKey(GoogleAPIKey.apiKey());

    locationServices.resolveLocationServices {
        success in
        if success {
            println("Location services success - \(self)")
        }
        else {
            println("Locations services not allowed - \(self)")
        }
    }

    return true
}

When I try to send the test push notification (with my app running on my iPhone 6+), I get the message that no devices have been registered. 当我尝试发送测试推送通知(我的应用程序在我的iPhone 6+上运行)时,我收到的消息是没有设备已注册。 I believe I have followed every step correctly but I am at a loss here. 我相信我已经正确地遵循了每一步,但我在这里不知所措。

application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()

The thing is, you are trying to register for remote notifications too soon, ie you should register for notifications after user allows your app to receive notifications. 问题是,您试图过早注册远程通知,即您应该在用户允许您的应用接收通知后注册通知。 You can get to know that in - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings; 您可以在- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings; method of app delegate. app委托的方法。 Just do application.registerForRemoteNotifications() inside the - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings method and everything will work. 只需在- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings执行application.registerForRemoteNotifications() - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings方法,一切都会正常工作。 Good Luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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