Forráskód Böngészése

Check SDK version at runtime

Sebastián Katzer 10 éve
szülő
commit
77eec5985b
2 módosított fájl, 33 hozzáadás és 32 törlés
  1. 10 11
      src/ios/APPLocalNotification.m
  2. 23 21
      src/ios/UIApplication+APPLocalNotification.m

+ 10 - 11
src/ios/APPLocalNotification.m

@@ -27,8 +27,6 @@
 #import "UIApplication+APPLocalNotification.h"
 #import "UILocalNotification+APPLocalNotification.h"
 
-#import <Availability.h>
-
 @interface APPLocalNotification ()
 
 // Retrieves the application state
@@ -411,16 +409,17 @@
  */
 - (void) registerPermission:(CDVInvokedUrlCommand*)command
 {
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
-
-    _command = command;
+    if ([[UIApplication sharedApplication]
+          respondsToSelector:@selector(registerUserNotificationSettings:)])
+    {
+        _command = command;
 
-    [self.commandDelegate runInBackground:^{
-        [self.app registerPermissionToScheduleLocalNotifications];
-    }];
-#else
-    [self hasPermission:command];
-#endif
+        [self.commandDelegate runInBackground:^{
+            [self.app registerPermissionToScheduleLocalNotifications];
+        }];
+    } else {
+        [self hasPermission:command];
+    }
 }
 
 #pragma mark -

+ 23 - 21
src/ios/UIApplication+APPLocalNotification.m

@@ -24,8 +24,6 @@
 #import "UIApplication+APPLocalNotification.h"
 #import "UILocalNotification+APPLocalNotification.h"
 
-#import <Availability.h>
-
 @implementation UIApplication (APPLocalNotification)
 
 #pragma mark -
@@ -36,19 +34,21 @@
  */
 - (BOOL) hasPermissionToScheduleLocalNotifications
 {
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
-    UIUserNotificationType types;
-    UIUserNotificationSettings *settings;
+    if ([[UIApplication sharedApplication]
+         respondsToSelector:@selector(registerUserNotificationSettings:)])
+    {
+        UIUserNotificationType types;
+        UIUserNotificationSettings *settings;
 
-    settings = [[UIApplication sharedApplication]
-                currentUserNotificationSettings];
+        settings = [[UIApplication sharedApplication]
+                    currentUserNotificationSettings];
 
-    types = UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound;
+        types = UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound;
 
-    return (settings.types & types);
-#else
-    return YES;
-#endif
+        return (settings.types & types);
+    } else {
+        return YES;
+    }
 }
 
 /**
@@ -56,18 +56,20 @@
  */
 - (void) registerPermissionToScheduleLocalNotifications
 {
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
-    UIUserNotificationType types;
-    UIUserNotificationSettings *settings;
+    if ([[UIApplication sharedApplication]
+         respondsToSelector:@selector(registerUserNotificationSettings:)])
+    {
+        UIUserNotificationType types;
+        UIUserNotificationSettings *settings;
 
-    types = UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound;
+        types = UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound;
 
-    settings = [UIUserNotificationSettings settingsForTypes:types
-                                                 categories:nil];
+        settings = [UIUserNotificationSettings settingsForTypes:types
+                                                     categories:nil];
 
-    [[UIApplication sharedApplication]
-     registerUserNotificationSettings:settings];
-#endif
+        [[UIApplication sharedApplication]
+         registerUserNotificationSettings:settings];
+    }
 }
 
 #pragma mark -