I am following the Parse tutorial to configure my device for 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:
I have added the requested code to my 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. 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;
method of app delegate. Just do application.registerForRemoteNotifications()
inside the - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
method and everything will work. Good Luck!
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.