From b18378505681818027a40c86f82125c1ecf747b8 Mon Sep 17 00:00:00 2001 From: Christos Vasilakis Date: Fri, 8 Aug 2014 17:02:30 +0300 Subject: [PATCH 1/2] care for iOS 8 registration when running under that platform --- src/ios/PushPlugin.m | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ios/PushPlugin.m b/src/ios/PushPlugin.m index 5622e7b..e7bd44f 100644 --- a/src/ios/PushPlugin.m +++ b/src/ios/PushPlugin.m @@ -40,8 +40,20 @@ - (void)register:(CDVInvokedUrlCommand *)command; { [self.commandDelegate runInBackground:^{ NSMutableDictionary *options = [self parseOptions:command]; [self saveConfig:options]; - [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert - | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound]; + + // when running under iOS 8 we will use the new API for APNS registration + #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 + if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) { + UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil]; + [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings]; + [[UIApplication sharedApplication] registerForRemoteNotifications]; + } else { + [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; + } + + #else + [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; + #endif CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_NO_RESULT]; [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]]; From 6679567067e7d22bba1d0f01155fbf821336b19f Mon Sep 17 00:00:00 2001 From: Christos Vasilakis Date: Fri, 8 Aug 2014 17:31:44 +0300 Subject: [PATCH 2/2] fix warning from the compiler --- src/ios/PushPlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ios/PushPlugin.m b/src/ios/PushPlugin.m index e7bd44f..c60051d 100644 --- a/src/ios/PushPlugin.m +++ b/src/ios/PushPlugin.m @@ -86,7 +86,7 @@ - (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [self.commandDelegate evalJs:@"cordova.require('org.jboss.aerogear.cordova.push.AeroGear.UnifiedPush').successCallback()"]; } failure:^(NSError *error) { NSString *errorMessage = [NSString stringWithFormat:@"Push registration Error: %@", error]; - NSLog(errorMessage); + NSLog(@"%@", errorMessage); CDVPluginResult *commandResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:errorMessage]; [self.commandDelegate sendPluginResult:commandResult callbackId:self.callbackId]; }];