|
|
@@ -57,9 +57,13 @@
|
|
|
[self.uploadManager saveTasks];
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-- (void)startLocation {
|
|
|
-
|
|
|
+//- (void)requestLocation
|
|
|
+//{
|
|
|
+// [self initLocationManager];
|
|
|
+// [self.locationManager requestLocation];
|
|
|
+//}
|
|
|
+-(void)initLocationManager
|
|
|
+{
|
|
|
if (self.locationManager) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -67,9 +71,14 @@
|
|
|
self.locationManager.delegate = self;
|
|
|
self.locationManager.allowsBackgroundLocationUpdates = YES;
|
|
|
self.locationManager.pausesLocationUpdatesAutomatically = NO; // 是否允许系统自动暂停定位
|
|
|
- self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;//设置定位精度
|
|
|
+ self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;//设置定位精度
|
|
|
+
|
|
|
self.locationManager.distanceFilter = 10; //不需要移动都可以刷新,不然不移动就不会执行定位,不定位的话,那么后台进程也就挂起了
|
|
|
[self.locationManager requestAlwaysAuthorization];
|
|
|
+}
|
|
|
+- (void)startLocation {
|
|
|
+ [self initLocationManager];
|
|
|
+
|
|
|
[self.locationManager startUpdatingLocation];
|
|
|
}
|
|
|
|
|
|
@@ -78,7 +87,7 @@
|
|
|
return;
|
|
|
}
|
|
|
[self.locationManager stopUpdatingLocation];
|
|
|
- self.locationManager = nil;
|
|
|
+// self.locationManager = nil;
|
|
|
}
|
|
|
|
|
|
- (void)receiveLogoutNotification:(NSNotification *)notification {
|
|
|
@@ -280,11 +289,11 @@
|
|
|
NSString *orderID = [aps objectForKey:@"order-id"];
|
|
|
if (RASingleton.sharedInstance.backgroundReportType == RABackgroundReportTypeAllow) {
|
|
|
|
|
|
- [self reportLocation:[RASingleton sharedInstance].currentLocation forOrder:orderID];
|
|
|
+ [self reportLastLocation:[RASingleton sharedInstance].lastLocation forOrder:orderID];
|
|
|
|
|
|
- } else if (RASingleton.sharedInstance.backgroundReportType == RABackgroundReportTypeAlways) {
|
|
|
+ } else if (RASingleton.sharedInstance.backgroundReportType == RABackgroundReportTypeAlwaysAsk) {
|
|
|
|
|
|
- [self reportLocationWithOrder:orderID];
|
|
|
+ [self askForReportLastLocation:orderID];
|
|
|
} else if (RASingleton.sharedInstance.backgroundReportType == RABackgroundReportTypeReject) {
|
|
|
|
|
|
[self rejectReportLocationWithReason:[NSString stringWithFormat:@"Driver %@ rejected to report location",RASingleton.sharedInstance.user] forOrder:orderID];
|
|
|
@@ -357,7 +366,19 @@
|
|
|
[RADataProvider reportLocationWithUserReason:reason forOrder:orderID];
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
+- (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 {
|
|
|
|
|
|
NSString *latLon = nil;
|
|
|
@@ -371,7 +392,36 @@
|
|
|
[RADataProvider reportCurrentLocation:latLon forOrderID:orderID];
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
+- (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 {
|
|
|
|
|
|
UIViewController *topVC = self.window.rootViewController;
|
|
|
@@ -408,18 +458,24 @@
|
|
|
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations {
|
|
|
if (locations.count) {
|
|
|
[RASingleton sharedInstance].currentLocation = [locations lastObject];
|
|
|
-
|
|
|
+ [RASingleton sharedInstance].lastLocation = [locations lastObject];
|
|
|
+ [RASingleton sharedInstance].lastLocationDateTime=[RAUtils current_date];
|
|
|
NSLog(@"location: %f, %f",[RASingleton sharedInstance].currentLocation.coordinate.latitude,[RASingleton sharedInstance].currentLocation.coordinate.longitude);
|
|
|
|
|
|
// 省电,停止不能超过三分钟
|
|
|
// [self performSelector:@selector(stopLocation) withObject:nil afterDelay:10]; // 获取到位置10s后关闭位置服务
|
|
|
// [self performSelector:@selector(startLocation) withObject:nil afterDelay:120]; // 获取到位置120s后重新打开位置服务
|
|
|
- CLLocationDistance distance = 500;
|
|
|
- NSTimeInterval time = 60;
|
|
|
+ //后台延迟定位3km,5分钟。
|
|
|
+ CLLocationDistance distance = 3000;
|
|
|
+ NSTimeInterval time = 60*5;
|
|
|
[manager allowDeferredLocationUpdatesUntilTraveled:distance timeout:time];
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+- (void)locationManager:(CLLocationManager *)manager
|
|
|
+ didFailWithError:(NSError *)error
|
|
|
+{
|
|
|
+ [RASingleton sharedInstance].currentLocation = nil;
|
|
|
+}
|
|
|
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
|
|
|
|
|
|
if (status == kCLAuthorizationStatusDenied) {
|