PhoneGap Push Plugin Does Not Register iOS 8 Device

拥有回忆 提交于 2019-12-13 05:16:25

问题


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

回答1:


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.




回答2:


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 }



来源:https://stackoverflow.com/questions/26087429/phonegap-push-plugin-does-not-register-ios-8-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!