diff --git a/src/ios/PushPlugin.m b/src/ios/PushPlugin.m index 7686ae9d..aab6ed5c 100644 --- a/src/ios/PushPlugin.m +++ b/src/ios/PushPlugin.m @@ -34,6 +34,7 @@ @implementation PushPlugin @synthesize notificationCallbackId; @synthesize callback; +#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending) - (void)unregister:(CDVInvokedUrlCommand*)command; { @@ -49,98 +50,129 @@ - (void)register:(CDVInvokedUrlCommand*)command; NSMutableDictionary* options = [command.arguments objectAtIndex:0]; -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 - UIUserNotificationType UserNotificationTypes = UIUserNotificationTypeNone; -#endif - 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; -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 + self.callback = [options objectForKey:@"ecb"]; + + if (!SYSTEM_VERSION_LESS_THAN(@"8.0")) { + + UIUserNotificationType UserNotificationTypes = UIUserNotificationTypeNone; + + if ([badgeArg isKindOfClass:[NSString class]]) + { + if ([badgeArg isEqualToString:@"true"]) { + UserNotificationTypes |= UIUserNotificationTypeBadge; + } + } + else if ([badgeArg boolValue]) { UserNotificationTypes |= UIUserNotificationTypeBadge; -#endif } - } - else if ([badgeArg boolValue]) { - notificationTypes |= UIRemoteNotificationTypeBadge; -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 - UserNotificationTypes |= UIUserNotificationTypeBadge; -#endif - } - if ([soundArg isKindOfClass:[NSString class]]) - { - if ([soundArg isEqualToString:@"true"]) { - notificationTypes |= UIRemoteNotificationTypeSound; -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 + if ([soundArg isKindOfClass:[NSString class]]) + { + if ([soundArg isEqualToString:@"true"]) { + UserNotificationTypes |= UIUserNotificationTypeSound; + } + } + else if ([soundArg boolValue]) { UserNotificationTypes |= UIUserNotificationTypeSound; -#endif - } - } - else if ([soundArg boolValue]) { - notificationTypes |= UIRemoteNotificationTypeSound; -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 - UserNotificationTypes |= UIUserNotificationTypeSound; -#endif - } + } - if ([alertArg isKindOfClass:[NSString class]]) - { - if ([alertArg isEqualToString:@"true"]) { - notificationTypes |= UIRemoteNotificationTypeAlert; -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 + if ([alertArg isKindOfClass:[NSString class]]) + { + if ([alertArg isEqualToString:@"true"]) { + UserNotificationTypes |= UIUserNotificationTypeAlert; + } + } + else if ([alertArg boolValue]) { UserNotificationTypes |= UIUserNotificationTypeAlert; -#endif - } - } - else if ([alertArg boolValue]) { - notificationTypes |= UIRemoteNotificationTypeAlert; -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 - UserNotificationTypes |= UIUserNotificationTypeAlert; -#endif - } - - notificationTypes |= UIRemoteNotificationTypeNewsstandContentAvailability; -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 - UserNotificationTypes |= UIUserNotificationActivationModeBackground; -#endif - - self.callback = [options objectForKey:@"ecb"]; + } - if (notificationTypes == UIRemoteNotificationTypeNone) - NSLog(@"PushPlugin.register: Push notification type is set to none"); + UserNotificationTypes |= UIUserNotificationActivationModeBackground; - isInline = NO; + isInline = NO; -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 - if ([[UIApplication sharedApplication]respondsToSelector:@selector(registerUserNotificationSettings:)]) { UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UserNotificationTypes categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; [[UIApplication sharedApplication] registerForRemoteNotifications]; + } else { - [[UIApplication sharedApplication] registerForRemoteNotificationTypes:notificationTypes]; - } -#else - [[UIApplication sharedApplication] registerForRemoteNotificationTypes:notificationTypes]; -#endif + UIRemoteNotificationType notificationTypes = UIRemoteNotificationTypeNone; + + + 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; + } + + + // Issue missing ios7 badge updates + // https://github.com/phonegap-build/PushPlugin/issues/365 + // Fixed when newsstand contant + // notificationTypes |= UIRemoteNotificationTypeNewsstandContentAvailability; + + if (notificationTypes == UIRemoteNotificationTypeNone) + NSLog(@"PushPlugin.register: Push notification type is set to none"); + + isInline = NO; + + [[UIApplication sharedApplication] registerForRemoteNotificationTypes:notificationTypes]; + + } // EO