Commit 77eec598 by Sebastián Katzer

Check SDK version at runtime

parent 5416f1c7
...@@ -27,8 +27,6 @@ ...@@ -27,8 +27,6 @@
#import "UIApplication+APPLocalNotification.h" #import "UIApplication+APPLocalNotification.h"
#import "UILocalNotification+APPLocalNotification.h" #import "UILocalNotification+APPLocalNotification.h"
#import <Availability.h>
@interface APPLocalNotification () @interface APPLocalNotification ()
// Retrieves the application state // Retrieves the application state
...@@ -411,16 +409,17 @@ ...@@ -411,16 +409,17 @@
*/ */
- (void) registerPermission:(CDVInvokedUrlCommand*)command - (void) registerPermission:(CDVInvokedUrlCommand*)command
{ {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 if ([[UIApplication sharedApplication]
respondsToSelector:@selector(registerUserNotificationSettings:)])
_command = command; {
_command = command;
[self.commandDelegate runInBackground:^{ [self.commandDelegate runInBackground:^{
[self.app registerPermissionToScheduleLocalNotifications]; [self.app registerPermissionToScheduleLocalNotifications];
}]; }];
#else } else {
[self hasPermission:command]; [self hasPermission:command];
#endif }
} }
#pragma mark - #pragma mark -
......
...@@ -24,8 +24,6 @@ ...@@ -24,8 +24,6 @@
#import "UIApplication+APPLocalNotification.h" #import "UIApplication+APPLocalNotification.h"
#import "UILocalNotification+APPLocalNotification.h" #import "UILocalNotification+APPLocalNotification.h"
#import <Availability.h>
@implementation UIApplication (APPLocalNotification) @implementation UIApplication (APPLocalNotification)
#pragma mark - #pragma mark -
...@@ -36,19 +34,21 @@ ...@@ -36,19 +34,21 @@
*/ */
- (BOOL) hasPermissionToScheduleLocalNotifications - (BOOL) hasPermissionToScheduleLocalNotifications
{ {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 if ([[UIApplication sharedApplication]
UIUserNotificationType types; respondsToSelector:@selector(registerUserNotificationSettings:)])
UIUserNotificationSettings *settings; {
UIUserNotificationType types;
UIUserNotificationSettings *settings;
settings = [[UIApplication sharedApplication] settings = [[UIApplication sharedApplication]
currentUserNotificationSettings]; currentUserNotificationSettings];
types = UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound; types = UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound;
return (settings.types & types); return (settings.types & types);
#else } else {
return YES; return YES;
#endif }
} }
/** /**
...@@ -56,18 +56,20 @@ ...@@ -56,18 +56,20 @@
*/ */
- (void) registerPermissionToScheduleLocalNotifications - (void) registerPermissionToScheduleLocalNotifications
{ {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 if ([[UIApplication sharedApplication]
UIUserNotificationType types; respondsToSelector:@selector(registerUserNotificationSettings:)])
UIUserNotificationSettings *settings; {
UIUserNotificationType types;
UIUserNotificationSettings *settings;
types = UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound; types = UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound;
settings = [UIUserNotificationSettings settingsForTypes:types settings = [UIUserNotificationSettings settingsForTypes:types
categories:nil]; categories:nil];
[[UIApplication sharedApplication] [[UIApplication sharedApplication]
registerUserNotificationSettings:settings]; registerUserNotificationSettings:settings];
#endif }
} }
#pragma mark - #pragma mark -
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment