Преглед изворни кода

1.修改iOS Apex Drivers位置上传参数。

Pen Li пре 7 година
родитељ
комит
2afb3d5751

+ 16 - 62
Redant Drivers/Apex And Drivers/AppDelegate.m

@@ -196,6 +196,7 @@
     
     if (!self.uploadManager) {
         self.uploadManager=[[RAUploadManager alloc] init];
+        self.uploadManager.maxRetry = 10;
     }
     [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
     
@@ -297,16 +298,17 @@
             
             NSString *orderID = [aps objectForKey:@"order-id"];
             BOOL tracing = [[aps objectForKey:@"tracing"] boolValue];
+            NSString *locationId = [aps objectForKey:@"location-id"];
             
             if (tracing) {
                 
                 if (RASingleton.sharedInstance.backgroundReportType == RABackgroundReportTypeAllow) {
                     
-                    [self reportLastLocation:[RASingleton sharedInstance].lastLocation forOrder:orderID];
+                    [self reportLastLocation:[RASingleton sharedInstance].lastLocation forOrder:orderID locationID:locationId];
                     
                 } else {
                     
-                    [self rejectReportLocationWithReason:[NSString stringWithFormat:@"Driver %@ rejected to report location",RASingleton.sharedInstance.user] forOrder:orderID];
+                    [self rejectReportLocationWithReason:[NSString stringWithFormat:@"Driver %@ rejected to report location",RASingleton.sharedInstance.user] forOrder:orderID locationID:locationId];
                 }
                 
                 return;
@@ -314,14 +316,14 @@
             
             if (RASingleton.sharedInstance.backgroundReportType == RABackgroundReportTypeAllow) {
                 
-                [self reportLastLocation:[RASingleton sharedInstance].lastLocation forOrder:orderID];
+                [self reportLastLocation:[RASingleton sharedInstance].lastLocation forOrder:orderID locationID:locationId];
                 
             } else if (RASingleton.sharedInstance.backgroundReportType == RABackgroundReportTypeAlwaysAsk) {
                 
-                [self askForReportLastLocation:orderID];
+                [self askForReportLastLocation:orderID locationID:locationId];
             } else if (RASingleton.sharedInstance.backgroundReportType == RABackgroundReportTypeReject) {
                 
-                [self rejectReportLocationWithReason:[NSString stringWithFormat:@"Driver %@ rejected to report location",RASingleton.sharedInstance.user] forOrder:orderID];
+                [self rejectReportLocationWithReason:[NSString stringWithFormat:@"Driver %@ rejected to report location",RASingleton.sharedInstance.user] forOrder:orderID locationID:locationId];
             }
             completionHandler(UIBackgroundFetchResultNewData);
         } else {
@@ -386,68 +388,20 @@
 
 #pragma mark - Report Location
 
-- (void)rejectReportLocationWithReason:(NSString *)reason forOrder:(NSString *)orderID {
+- (void)rejectReportLocationWithReason:(NSString *)reason forOrder:(NSString *)orderID locationID:(NSString *)locationId {
     dispatch_async(dispatch_get_global_queue(0, 0), ^{
-        [RADataProvider reportLocationWithUserReason:reason forOrder:orderID];
+        [RADataProvider reportLocationWithUserReason:reason forOrder:orderID locationID:locationId];
     });
 }
-- (void)reportLastLocation:(CLLocation *)location forOrder:(NSString *)orderID {
-    
-    NSString *latLon = nil;
-    if (location) {
-        latLon = [NSString stringWithFormat:@"%f,%f",location.coordinate.latitude,location.coordinate.longitude];
-        
-    } else {
-        latLon = @"-999,-999";
-    }
-    dispatch_async(dispatch_get_global_queue(0, 0), ^{
-        [RADataProvider reportLastLocation:latLon forOrderID:orderID];
-    });
-}
-- (void)reportLocation:(CLLocation *)location forOrder:(NSString *)orderID {
+
+- (void)reportLastLocation:(CLLocation *)location forOrder:(NSString *)orderID locationID:(NSString *)locationId {
     
-    NSString *latLon = nil;
-    if (location) {
-        latLon = [NSString stringWithFormat:@"%f,%f",location.coordinate.latitude,location.coordinate.longitude];
-        
-    } else {
-        latLon = @"-999,-999";
-    }
     dispatch_async(dispatch_get_global_queue(0, 0), ^{
-        [RADataProvider reportCurrentLocation:latLon forOrderID:orderID];
+        [RADataProvider reportLastLocation:location forOrderID:orderID locationID:locationId];
     });
 }
-- (void)askForReportLastLocation:(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) {
-            
-            [self rejectReportLocationWithReason:[NSString stringWithFormat:@"Driver %@ cancel to report location",RASingleton.sharedInstance.user] forOrder:orderID];
-            
-        }];
-        
-        __weak typeof(self) weakSelf = self;
-        UIAlertAction *reportAction = [UIAlertAction actionWithTitle:@"Report" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
-            
-            [weakSelf reportLastLocation:[RASingleton sharedInstance].lastLocation 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]];
-    }
-}
-- (void)reportLocationWithOrder:(NSString *)orderID {
+
+- (void)askForReportLastLocation:(NSString *)orderID locationID:(NSString *)locationId{
     
     UIViewController *topVC = self.window.rootViewController;
     while (topVC.presentedViewController) {
@@ -458,14 +412,14 @@
         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) {
             
-            [self rejectReportLocationWithReason:[NSString stringWithFormat:@"Driver %@ cancel to report location",RASingleton.sharedInstance.user] forOrder:orderID];
+            [self rejectReportLocationWithReason:[NSString stringWithFormat:@"Driver %@ cancel to report location",RASingleton.sharedInstance.user] forOrder:orderID locationID:locationId];
             
         }];
         
         __weak typeof(self) weakSelf = self;
         UIAlertAction *reportAction = [UIAlertAction actionWithTitle:@"Report" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
             
-            [weakSelf reportLocation:[RASingleton sharedInstance].currentLocation forOrder:orderID];
+            [weakSelf reportLastLocation:[RASingleton sharedInstance].lastLocation forOrder:orderID locationID:locationId];
             
         }];
         

+ 3 - 4
Redant Drivers/Apex And Drivers/RADataProvider.h

@@ -8,7 +8,7 @@
 
 #import <Foundation/Foundation.h>
 
-@class RAEditImageBaseModel;
+@class RAEditImageBaseModel,CLLocation;
 @interface RADataProvider : NSObject
 
 + (NSDictionary *)requestLogin:(NSString *)user password:(NSString *)pwd;
@@ -29,10 +29,9 @@
 
 + (NSDictionary *)uploadFile:(NSString *)filePath parameters:(NSMutableDictionary *)params;///<同步上传文件
 
-+ (NSDictionary *)reportCurrentLocation:(NSString *)location forOrderID:(NSString *)orderID;
-+ (NSDictionary *)reportLastLocation:(NSString *)location forOrderID:(NSString *)orderID;
++ (NSDictionary *)reportLastLocation:(CLLocation *)location forOrderID:(NSString *)orderID locationID:(NSString *)locationId;
 
-+ (NSDictionary *)reportLocationWithUserReason:(NSString *)option forOrder:(NSString *)orderID;
++ (NSDictionary *)reportLocationWithUserReason:(NSString *)option forOrder:(NSString *)orderID locationID:(NSString *)locationId;
 
 + (NSDictionary *)bindNitificationToken:(NSString *)token;
 

+ 29 - 19
Redant Drivers/Apex And Drivers/RADataProvider.m

@@ -11,6 +11,7 @@
 #import "ZipArchive.h"
 #import "AESCrypt.h"
 #import "RAOfflineHandler.h"
+#import <CoreLocation/CoreLocation.h>
 
 
 @implementation RADataProvider
@@ -315,36 +316,41 @@
 + (NSDictionary *)uploadFile:(NSString *)filePath parameters:(NSMutableDictionary *)params {
     return [self upload:URL_UPLOAD parameters:params file:filePath];
 }
-+ (NSDictionary *)reportLastLocation:(NSString *)location forOrderID:(NSString *)orderID {
+
++ (NSDictionary *)reportLastLocation:(CLLocation *)location forOrderID:(NSString *)orderID locationID:(NSString *)locationId {
     
     NSMutableDictionary *params = [NSMutableDictionary dictionary];
+    
+    NSString *latLon = nil;
     if (location) {
-        [params setObject:location forKey:@"location"];
+        latLon = [NSString stringWithFormat:@"%f,%f",location.coordinate.latitude,location.coordinate.longitude];
+        
+    } else {
+        latLon = @"-999,-999";
     }
+    
+    if (latLon) {
+        [params setObject:latLon forKey:@"location"];
+    }
+    
     if (orderID) {
         [params setObject:orderID forKey:@"orderID"];
     }
-    NSString * lastLocationDateTime = RASingleton.sharedInstance.lastLocationDateTime;
-    if(lastLocationDateTime.length>0)
-    {
-        [params setObject:lastLocationDateTime forKey:@"lastLocationDateTime"];
-    }
-    [params setObject:@(0) forKey:@"userOption"]; // 0 表示同意发送位置
-    
-    NSData* json=[self get_json:URL_REPORT_LOCATION parameters:params  file:nil];
     
-    return [self handleJsonData:json];
-}
-+ (NSDictionary *)reportCurrentLocation:(NSString *)location forOrderID:(NSString *)orderID {
-    
-    NSMutableDictionary *params = [NSMutableDictionary dictionary];
     if (location) {
-        [params setObject:location forKey:@"location"];
+        [params setObject:@(location.speed) forKey:@"speed"];
+        [params setObject:@([location.timestamp timeIntervalSince1970]) forKey:@"timestamp"];
     }
-    if (orderID) {
-        [params setObject:orderID forKey:@"orderID"];
+    
+    if (locationId) {
+        [params setObject:locationId forKey:@"locationId"];
     }
     
+    NSString * lastLocationDateTime = RASingleton.sharedInstance.lastLocationDateTime;
+    if(lastLocationDateTime.length>0)
+    {
+        [params setObject:lastLocationDateTime forKey:@"lastLocationDateTime"];
+    }
     [params setObject:@(0) forKey:@"userOption"]; // 0 表示同意发送位置
     
     NSData* json=[self get_json:URL_REPORT_LOCATION parameters:params  file:nil];
@@ -352,7 +358,7 @@
     return [self handleJsonData:json];
 }
 
-+ (NSDictionary *)reportLocationWithUserReason:(NSString *)reason forOrder:(NSString *)orderID {
++ (NSDictionary *)reportLocationWithUserReason:(NSString *)reason forOrder:(NSString *)orderID locationID:(NSString *)locationId {
     
     NSMutableDictionary *params = [NSMutableDictionary dictionary];
     if (reason) {
@@ -362,6 +368,10 @@
         [params setObject:orderID forKey:@"orderID"];
     }
     
+    if (locationId) {
+        [params setObject:locationId forKey:@"locationId"];
+    }
+    
     [params setObject:@(1) forKey:@"userOption"]; // 1 表示不同意发送位置
     
     NSData* json=[self get_json:URL_REPORT_LOCATION parameters:params  file:nil];

+ 7 - 7
Redant Drivers/Apex And Drivers/Update/RAOrderEditViewController.m

@@ -42,13 +42,13 @@
 - (void)setItems:(NSArray<RAEditBaseModel *> *)items {
     
     NSMutableArray *tmpItems = [items mutableCopy];
-    [tmpItems addObject:@{
-                          @"type" : @6,
-                          @"title" : @"Container Photo",
-                          @"required" : @(YES),
-                          @"photos" : @[@{@"placeHolder":@"btn_add_photo"},@{@"placeHolder":@"btn_add_photo"},@{@"placeHolder":@"btn_add_photo"},@{@"placeHolder":@"btn_add_photo"},@{@"placeHolder":@"btn_add_photo"},@{@"placeHolder":@"btn_add_photo"}],
-                          @"key" : @"test_photo"
-                          }];
+//    [tmpItems addObject:@{
+//                          @"type" : @6,
+//                          @"title" : @"Container Photo",
+//                          @"required" : @(YES),
+//                          @"photos" : @[@{@"placeHolder":@"btn_add_photo"},@{@"placeHolder":@"btn_add_photo"},@{@"placeHolder":@"btn_add_photo"},@{@"placeHolder":@"btn_add_photo"},@{@"placeHolder":@"btn_add_photo"},@{@"placeHolder":@"btn_add_photo"}],
+//                          @"key" : @"test_photo"
+//                          }];
     
     NSMutableArray *itemArr = [NSMutableArray arrayWithCapacity:items.count];
     for (int i = 0; i < tmpItems.count; i++) {