我正在按照Parse教程配置我的设备以进行推送通知。
https://www.parse.com/tutorials/ios-push-notifications
我的苹果开发者屏幕显示已启用:
我已经安装了推送证书:
我已将.p12证书添加到Parse上的设置部分:
我已将请求的代码添加到我的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
}
当我尝试发送测试推送通知(我的应用程序在我的iPhone 6+上运行)时,我收到的消息是没有设备已注册。我相信我已经正确地遵循了每一步,但我在这里不知所措。
答案 0 :(得分:0)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
问题是,您正试图过早注册远程通知,即您应该在用户允许您的应用接收通知后注册通知。您可以在应用委托的- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings;
方法中了解这一点。只需在application.registerForRemoteNotifications()
方法中执行- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
即可。祝你好运!