PhoneGap Push Plugin doesn't register iOS 8 device
Plugin on version 2.3.1, iOS 8.0, iPhone 5. Everything worked to find up to iOS 8. I updated the plugin to 2.0.5. When the register is called, neither a successful nor a response is accepted:
window.plugins.pushNotification.register(
// tokenHandler (iOS ony) - called when the device has registeredwith a unique device token.
function (result) {
alert('device token = ' + result);
},
function(error) {
alert('error = ' + JSON.stringify(error));
},
{
"badge":"true",
"sound":"true",
"alert":"true",
"ecb":"onNotificationAPN"
}
);
source to share
Check pull requests on github.
https://github.com/phonegap-build/PushPlugin/pulls
Includes iOS8 fixes. It looks like they are not yet merged into the phonegap-build repository.
iOS8 has changed the way we register and handle push notifications, so there are some code changes that will need to be updated to support iOS8.
source to share
Modify PushPlugin.m
-
(voids) case: command (CDVInvokedUrlCommand *); {self.callbackId = command.callbackId;
NSMutableDictionary * options = [command.arguments objectAtIndex: 0];
UIRemoteNotificationType notificationTypes = UIRemoteNotificationTypeNone; id badgeArg = [objectForKey options: @ "badge"]; id soundArg = [objectForKey options: @ "sound"]; id alertArg = [objectForKey options: @ "alert"];
if ([badgeArg isKindOfClass: [NSString class]]) {if ([badgeArg isEqualToString: @ "true"]) notificationTypes | = UIRemoteNotificationTypeBadge; } else if ([badgeArg boolValue]) notificationTypes | = UIRemoteNotificationTypeBadge;
if ([soundArg isKindOfClass: [NSString class]]) {if ([soundArg isEqualToString: @ "true"]) notificationTypes | = UIRemoteNotificationTypeSound; } else if ([soundArg boolValue]) notificationTypes | = UIRemoteNotificationTypeSound;
if ([alertArg isKindOfClass: [NSString class]]) {if ([alertArg isEqualToString: @ "true"]) notificationTypes | = UIRemoteNotificationTypeAlert; } else if ([alertArg boolValue]) notificationTypes | = UIRemoteNotificationTypeAlert;
self.callback = [options objectForKey: @ "ecb"]; if (self.callback! = nil & & [self.callback length]) {[[NSUserDefaults standardUserDefaults] setObject: self.callback forKey: @ "CallBack"]; }
if (notificationTypes == UIRemoteNotificationTypeNone) NSLog (@ "PushPlugin.register: Push Push type set to none);
isInline = NO;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: notificationTypes];
if (notificationMessage) // if there is a pending launch notification [self notificationReceived]; // go ahead and process it}
**
Change as
**
-
(voids) case: command (CDVInvokedUrlCommand *); {self.callbackId = command.callbackId;
NSMutableDictionary * options = [command.arguments objectAtIndex: 0];
UIRemoteNotificationType notificationTypes = UIRemoteNotificationTypeNone; id badgeArg = [objectForKey options: @ "badge"]; id soundArg = [objectForKey options: @ "sound"]; id alertArg = [objectForKey options: @ "alert"];
if ([badgeArg isKindOfClass: [NSString class]]) {if ([badgeArg isEqualToString: @ "true"]) notificationTypes | = UIRemoteNotificationTypeBadge; } else if ([badgeArg boolValue]) notificationTypes | = UIRemoteNotificationTypeBadge;
if ([soundArg isKindOfClass: [NSString class]]) {if ([soundArg isEqualToString: @ "true"]) notificationTypes | = UIRemoteNotificationTypeSound; } else if ([soundArg boolValue]) notificationTypes | = UIRemoteNotificationTypeSound;
if ([alertArg isKindOfClass: [NSString class]]) {if ([alertArg isEqualToString: @ "true"]) notificationTypes | = UIRemoteNotificationTypeAlert; } else if ([alertArg boolValue]) notificationTypes | = UIRemoteNotificationTypeAlert;
self.callback = [options objectForKey: @ "ecb"]; if (self.callback! = nil & & [self.callback length]) {[[NSUserDefaults standardUserDefaults] setObject: self.callback forKey: @ "CallBack"]; }
if (notificationTypes == UIRemoteNotificationTypeNone) NSLog (@ "PushPlugin.register: Push Push type set to none);
isInline = NO;
// [[UIApplication sharedApplication] registerForRemoteNotificationTypes: notificationTypes]; // For Iphone 8 if ([[[UIDevice currentDevice] systemVersion] floatValue]> = 8.0) {[[UIApplication sharedApplication] registerUserNotificationSettings: [UIUserNotificationSettings settingsForTypes: (UIUserNotificationTypeSound | UIUserNotificationType [[UAppication sharedApplication] registerForRemoteNotifications]; } else {[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)]; }
if (notificationMessage) // if there is a pending launch notification [self notificationReceived]; // go ahead and process it}