简体   繁体   中英

PhoneGap Push Plugin Does Not Register iOS 8 Device

The plugin at version 2.3.1, iOS 8.0, iPhone 5. Everything worked find before iOS 8. I upgraded the plugin, before it was 2.0.5. Neither a success nor an error response is received when calling register:

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"
      }
    );

Check out the pull requests on github.

https://github.com/phonegap-build/PushPlugin/pulls

There are lots of iOS8 Fixes included. It doesn't look like they are merged into the phonegap-build repository yet.

iOS8 changed the way they register and handle push notifications so there are some code changes you will need to update to support iOS8.

Change the PushPlugin.m

  • (void)register:(CDVInvokedUrlCommand*)command; { self.callbackId = command.callbackId;

    NSMutableDictionary* options = [command.arguments objectAtIndex:0];

    UIRemoteNotificationType notificationTypes = UIRemoteNotificationTypeNone; id badgeArg = [options objectForKey:@"badge"]; id soundArg = [options objectForKey:@"sound"]; id alertArg = [options objectForKey:@"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 notification type is set to none");

    isInline = NO;

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:notificationTypes];

    if (notificationMessage) // if there is a pending startup notification [self notificationReceived]; // go ahead and process it }

**

Change like this

**

  • (void)register:(CDVInvokedUrlCommand*)command; { self.callbackId = command.callbackId;

    NSMutableDictionary* options = [command.arguments objectAtIndex:0];

    UIRemoteNotificationType notificationTypes = UIRemoteNotificationTypeNone; id badgeArg = [options objectForKey:@"badge"]; id soundArg = [options objectForKey:@"sound"]; id alertArg = [options objectForKey:@"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 notification type is 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 | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; [[UIApplication sharedApplication] registerForRemoteNotifications]; } else { [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)]; }

    if (notificationMessage) // if there is a pending startup notification [self notificationReceived]; // go ahead and process it }

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.

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