فهرست منبع

1.修改iOS Apex Drivers位置上传处理。

Pen Li 7 سال پیش
والد
کامیت
90c93d7057

+ 75 - 13
Redant Drivers/Apex And Drivers/AppDelegate.m

@@ -82,18 +82,6 @@ static const NSInteger OrderTypeNew = 2;
     self.locationManager = nil;
 }
 
-- (void)reportLocation:(CLLocation *)location forOrder:(NSString *)orderID {
-    
-    if (location) {
-        NSString *latLon = [NSString stringWithFormat:@"%f,%f",location.coordinate.latitude,location.coordinate.longitude];
-        dispatch_async(dispatch_get_global_queue(0, 0), ^{
-           [RADataProvider reportCurrentLocation:latLon forOrderID:orderID];
-        });
-    } else {
-        
-    }
-}
-
 - (void)receiveLogoutNotification:(NSNotification *)notification {
     [self showLoginVC];
 }
@@ -170,6 +158,7 @@ static const NSInteger OrderTypeNew = 2;
     if (!self.uploadManager) {
         self.uploadManager=[[RAUploadManager alloc] init];
     }
+    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
 }
 
 - (void)applicationWillTerminate:(UIApplication *)application {
@@ -252,8 +241,16 @@ static const NSInteger OrderTypeNew = 2;
         NSDictionary *aps = [userInfo objectForKey:@"aps"];
         NSInteger report_location = [[aps objectForKey:@"report-location"] integerValue];
         if (report_location == 1) {
+            
             NSString *orderID = [aps objectForKey:@"order-id"];
-            [self reportLocation:[RASingleton sharedInstance].currentLocation forOrder:orderID];
+            if (RASingleton.sharedInstance.backgroundReportType == RABackgroundReportTypeAllow) {
+                
+                [self reportLocation:[RASingleton sharedInstance].currentLocation forOrder:orderID];
+                
+            } else if (RASingleton.sharedInstance.backgroundReportType == RABackgroundReportTypeAlways) {
+                
+                [self reportLocationWithOrder:orderID];
+            }
             completionHandler(UIBackgroundFetchResultNewData);
         } else {
             /**
@@ -285,6 +282,71 @@ static const NSInteger OrderTypeNew = 2;
     }
 }
 
+#pragma mark - Local Notification
+
+- (void)sendLocalNotification:(NSString *)title message:(NSString *)msg {
+    
+    // 创建Content
+    UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
+    content.title = title;
+    content.body = msg;
+    content.badge = @([UIApplication sharedApplication].applicationIconBadgeNumber + 1);
+
+    // 创建Request,保证ID一致
+    UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"local_notification" content:content trigger:nil];
+    
+    // 发送
+    [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
+        if (!error) {
+            NSLog(@"发送本地通知:%@",request.identifier);
+        }
+    }];
+    
+}
+
+#pragma mark - Report Location
+
+- (void)reportLocation:(CLLocation *)location forOrder:(NSString *)orderID {
+    
+    if (location) {
+        NSString *latLon = [NSString stringWithFormat:@"%f,%f",location.coordinate.latitude,location.coordinate.longitude];
+        dispatch_async(dispatch_get_global_queue(0, 0), ^{
+            [RADataProvider reportCurrentLocation:latLon forOrderID:orderID];
+        });
+    } else {
+        
+    }
+}
+
+- (void)reportLocationWithOrder:(NSString *)orderID {
+    
+    UIViewController *topVC = self.window.rootViewController;
+    while (topVC.presentedViewController) {
+        topVC = topVC.presentedViewController;
+    }
+    
+    if (topVC) {
+        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"Report Location For Order:%@",orderID] preferredStyle:UIAlertControllerStyleAlert];
+        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            
+        }];
+        
+        __weak typeof(self) weakSelf = self;
+        UIAlertAction *reportAction = [UIAlertAction actionWithTitle:@"Report" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
+            
+            [weakSelf reportLocation:[RASingleton sharedInstance].currentLocation forOrder:orderID];
+            
+        }];
+        
+        [alertVC addAction:cancelAction];
+        [alertVC addAction:reportAction];
+        
+        [topVC presentViewController:alertVC animated:YES completion:nil];
+        
+        [self sendLocalNotification:@"Report Location Notification" message:[NSString stringWithFormat:@"The Apex ask your location for order:%@",orderID]];
+    }
+}
+
 #pragma mark - LocationManager Delegate
 
 - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations {

+ 108 - 75
Redant Drivers/Apex And Drivers/Login/LoginViewController.m

@@ -21,11 +21,118 @@
     return loginVC;
 }
 
+- (void)viewDidLoad
+{
+    [super viewDidLoad];
+    [self.checkSavePassword setImage:[UIImage imageNamed:@"unchecked_32.png"] forState:UIControlStateNormal];
+    [self.checkSavePassword setImage:[UIImage imageNamed:@"checked_32.png"] forState:UIControlStateSelected];
+    
+    
+    self.editUser.delegate = self;
+    self.editPassword.delegate = self;
+    self.resize = false;
+    self.ioffset = 0;
+    
+    
+    self.title=@"Login";
+    
+    
+    [self.checkSavePassword addTarget:self action:@selector(checkboxClick:) forControlEvents:UIControlEventTouchUpInside];
+    //    [self.view addSubview:checkSavePassword];
+    // Do any additional setup after loading the view, typically from a nib.
+    
+    self.mum.backgroundColor = [UIColor clearColor];
+    
+    NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
+    
+    NSString* shortNum =[infoDict objectForKey:@"CFBundleShortVersionString"];
+    NSString* versionNum =[infoDict objectForKey:@"CFBundleVersion"];
+    versionNum = [NSString stringWithFormat:@"ver:%@.A%@",shortNum,versionNum];
+    
+    self.verLabel.text = versionNum;
+}
+
+- (void)viewWillAppear:(BOOL)animated {
+    [super viewWillAppear:animated];
+    
+    NSString * user = RASingleton.sharedInstance.savedUser;
+    NSString *password = RASingleton.sharedInstance.savedPassword;
+    
+    if(user.length>0&&password.length>0)
+    {
+        self.editUser.text=user;
+        self.editPassword.text=password;
+        self.checkSavePassword.selected=true;
+        
+    }
+    
+    [self clearNavigationbar];
+    [self configureNavigationBar];
+}
+
+- (void)viewDidAppear:(BOOL)animated {
+    
+    [super viewDidAppear:animated];
+    
+//    if (RASingleton.sharedInstance.backgroundReportType == RABackgroundReportTypeNone) {
+    
+        UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:@"Apex & Drivers need background send location" preferredStyle:UIAlertControllerStyleAlert];
+        
+        UIAlertAction *rejectAction = [UIAlertAction actionWithTitle:@"Reject" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            RASingleton.sharedInstance.backgroundReportType = RABackgroundReportTypeReject;
+        }];
+        
+        UIAlertAction *alwaysAction = [UIAlertAction actionWithTitle:@"Always ask" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            RASingleton.sharedInstance.backgroundReportType = RABackgroundReportTypeAlways;
+        }];
+        
+        UIAlertAction *allowAction = [UIAlertAction actionWithTitle:@"Allow" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            RASingleton.sharedInstance.backgroundReportType = RABackgroundReportTypeAllow;
+        }];
+        
+        [alertVC addAction:rejectAction];
+        [alertVC addAction:alwaysAction];
+        [alertVC addAction:allowAction];
+        
+        [self presentViewController:alertVC animated:YES completion:nil];
+        
+//    }
+}
+
+- (void)didReceiveMemoryWarning {
+    [super didReceiveMemoryWarning];
+    // Dispose of any resources that can be recreated.
+}
+
+#pragma mark - Config
+
+- (void)clearNavigationbar {
+    self.tabBarController.navigationItem.leftBarButtonItem = nil;
+    self.tabBarController.navigationItem.leftBarButtonItems = nil;
+    self.tabBarController.navigationItem.titleView = nil;
+    self.tabBarController.navigationItem.title = nil;
+    self.tabBarController.navigationItem.rightBarButtonItem = nil;
+    self.tabBarController.navigationItem.rightBarButtonItems = nil;
+}
+
+- (void)configureNavigationBar {
+    
+    if (self.navigationController && !self.navigationController.isNavigationBarHidden) {
+        
+        UIImage *logo = [[UIImage imageNamed:@"apexlogo-2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
+        UIBarButtonItem *logoItem = [[UIBarButtonItem alloc] initWithImage:logo landscapeImagePhone:logo style:UIBarButtonItemStylePlain target:nil action:nil];
+        logoItem.enabled = NO;
+        self.tabBarController.navigationItem.leftBarButtonItem = logoItem;
+    }
+}
+
 - (void)clear {
     self.editPassword.text = nil;
     self.editUser.text = nil;
 }
 
+#pragma mark - Action
+
 - (IBAction)RetrieveButtonClick:(UIButton *)sender {
 //    [self performSegueWithIdentifier:@"RETRIEVE" sender:self];
     
@@ -137,81 +244,7 @@
 //- (IBAction)onRetrievePassword:(UIButton *)sender {
 //}
 
-- (void)viewDidLoad
-{
-    [super viewDidLoad];
-    [self.checkSavePassword setImage:[UIImage imageNamed:@"unchecked_32.png"] forState:UIControlStateNormal];
-    [self.checkSavePassword setImage:[UIImage imageNamed:@"checked_32.png"] forState:UIControlStateSelected];
-    
-    
-    self.editUser.delegate = self;
-    self.editPassword.delegate = self;
-    self.resize = false;
-    self.ioffset = 0;
-    
-    
-    self.title=@"Login";
-    
-    
-    [self.checkSavePassword addTarget:self action:@selector(checkboxClick:) forControlEvents:UIControlEventTouchUpInside];
-    //    [self.view addSubview:checkSavePassword];
-    // Do any additional setup after loading the view, typically from a nib.
-    
-    self.mum.backgroundColor = [UIColor clearColor];
-    
-    NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
-    
-    NSString* shortNum =[infoDict objectForKey:@"CFBundleShortVersionString"];
-    NSString* versionNum =[infoDict objectForKey:@"CFBundleVersion"];
-    versionNum = [NSString stringWithFormat:@"ver:%@.A%@",shortNum,versionNum];
-    
-    self.verLabel.text = versionNum;
-}
-
-- (void)viewWillAppear:(BOOL)animated {
-    [super viewWillAppear:animated];
-    
-    NSString * user = RASingleton.sharedInstance.savedUser;
-    NSString *password = RASingleton.sharedInstance.savedPassword;
-    
-    if(user.length>0&&password.length>0)
-    {
-        self.editUser.text=user;
-        self.editPassword.text=password;
-        self.checkSavePassword.selected=true;
-        
-    }
-    
-    [self clearNavigationbar];
-    [self configureNavigationBar];
-}
-
-- (void)clearNavigationbar {
-    self.tabBarController.navigationItem.leftBarButtonItem = nil;
-    self.tabBarController.navigationItem.leftBarButtonItems = nil;
-    self.tabBarController.navigationItem.titleView = nil;
-    self.tabBarController.navigationItem.title = nil;
-    self.tabBarController.navigationItem.rightBarButtonItem = nil;
-    self.tabBarController.navigationItem.rightBarButtonItems = nil;
-}
-
-- (void)configureNavigationBar {
-    
-    if (self.navigationController && !self.navigationController.isNavigationBarHidden) {
-        
-        UIImage *logo = [[UIImage imageNamed:@"apexlogo-2"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
-        UIBarButtonItem *logoItem = [[UIBarButtonItem alloc] initWithImage:logo landscapeImagePhone:logo style:UIBarButtonItemStylePlain target:nil action:nil];
-        logoItem.enabled = NO;
-        self.tabBarController.navigationItem.leftBarButtonItem = logoItem;
-    }
-}
-
-
-- (void)didReceiveMemoryWarning
-{
-    [super didReceiveMemoryWarning];
-    // Dispose of any resources that can be recreated.
-}
+#pragma mark - TextFied Delegate
 
 -(BOOL)textFieldShouldReturn:(UITextField *)textField {
     

+ 10 - 0
Redant Drivers/Apex And Drivers/RASingleton.h

@@ -8,6 +8,14 @@
 
 #import <Foundation/Foundation.h>
 
+typedef enum {
+    RABackgroundReportTypeNone = 0, ///<没有设置
+    RABackgroundReportTypeReject = 1, ///< 拒绝
+    RABackgroundReportTypeAlways = 2, ///< 每次询问
+    RABackgroundReportTypeAllow = 3 ///< 同意
+    
+} RABackgroundReportType;
+
 @class CLLocation;
 @interface RASingleton : NSObject
 
@@ -26,6 +34,8 @@
 
 @property (nonatomic,strong) NSOperationQueue *networkQueue;
 
+@property (nonatomic,assign) RABackgroundReportType backgroundReportType;///<后台位置报告权限类型
+
 - (void)saveUserInfo;
 
 - (NSString *)savedUser;

+ 19 - 0
Redant Drivers/Apex And Drivers/RASingleton.m

@@ -13,6 +13,7 @@ static RASingleton *singleton;
 @implementation RASingleton {
     NSString *_secretKey;
 }
+@synthesize backgroundReportType = _backgroundReportType;
 
 + (instancetype)sharedInstance {
     
@@ -168,4 +169,22 @@ static RASingleton *singleton;
     return _networkQueue;
 }
 
+#pragma mark - Backgroud Report Location Permission
+
+- (void)setBackgroundReportType:(RABackgroundReportType)backgroundReportType {
+    _backgroundReportType = backgroundReportType;
+    
+    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+    [defaults setInteger:_backgroundReportType forKey:@"backgroundReportLocationPermissionType"];
+    [defaults synchronize];
+}
+
+- (RABackgroundReportType)backgroundReportType {
+    if (_backgroundReportType == 0) {
+        NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
+        _backgroundReportType = (RABackgroundReportType)[defaults integerForKey:@"backgroundReportLocationPermissionType"];
+    }
+    return _backgroundReportType;
+}
+
 @end