Просмотр исходного кода

1.修改iOS Apex Driver首页权限检查。

Pen Li 7 лет назад
Родитель
Сommit
1034f5872b
1 измененных файлов с 51 добавлено и 0 удалено
  1. 51 0
      Redant Drivers/Apex And Drivers/Home/RAHomeViewController.m

+ 51 - 0
Redant Drivers/Apex And Drivers/Home/RAHomeViewController.m

@@ -17,6 +17,7 @@
 #import "RAHomeHeaderView.h"
 #import "RAMessageViewController.h"
 #import "RASettingViewController.h"
+#import <CoreLocation/CoreLocation.h>
 
 @implementation RAHomeSectionModel
 
@@ -94,6 +95,8 @@
     [super viewDidLoad];
     // Do any additional setup after loading the view.
     
+    [self checkPermission];
+    
     [self configureNavigationBar];
     [self configureTable];
     [self registNotification];
@@ -181,6 +184,54 @@
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveReloadNotification:) name:RANotificationReloadHome object:nil];
 }
 
+- (void)checkPermission {
+    
+    CLAuthorizationStatus locationAuthoriztionAstatus = [CLLocationManager authorizationStatus];
+    [[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
+       
+        UNAuthorizationStatus notificationAuthorizationStatus = settings.authorizationStatus;
+        
+        BOOL enableLocation = locationAuthoriztionAstatus != kCLAuthorizationStatusRestricted && locationAuthoriztionAstatus != kCLAuthorizationStatusDenied;
+        BOOL enableRemoteNotification = notificationAuthorizationStatus != UNAuthorizationStatusDenied;
+        
+        if (!enableLocation | !enableRemoteNotification) {
+            
+            NSMutableString *msg = [NSMutableString stringWithString:@"you should open"];
+            
+            if (!enableLocation) {
+                [msg appendString:@" location permissions"];
+            }
+            
+            if (!enableRemoteNotification) {
+                
+                if (!enableLocation) {
+                    [msg appendString:@" and notification permissions"];
+                } else {
+                    [msg appendString:@" notification permissions"];
+                }
+            }
+            
+            dispatch_async(dispatch_get_main_queue(), ^{
+                
+                UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:msg preferredStyle:UIAlertControllerStyleAlert];
+                UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+                    
+                    NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
+                    if ([[UIApplication sharedApplication]canOpenURL:url]) {
+                        [[UIApplication sharedApplication]openURL:url];
+                    }
+                }];
+                
+                [alertVC addAction:okAction];
+                
+                [self presentViewController:alertVC animated:YES completion:nil];
+                
+            });
+        }
+    }];
+    
+}
+
 #pragma mark - Action
 
 - (void)uploadListItemClick:(UIBarButtonItem *)sender {