This is the 15th day of my participation in the August More Text Challenge. For details, see “juejin.cn/post/698796…
preface
This paper mainly
- Limit merchant positioning outside mainland China
Judge by latitude and longitude. Use Autonavi SDK for judgment. (If the location information is entered manually, reverse geocoding is performed to obtain the latitude and longitude and then judge)
- Optimal positioning permission check processing logic: kCLAuthorizationStatusNotDetermined case processing
The user does not select whether to use location services (pop-ups are not selected, or there is no pop-ups at all)
[AMapLocationKit] to use in iOS version 11 or more background location services, you need to implement amapLocationManager: doRequireLocationAuth: proxy method 】
I, boundary _ external positioning
Principle: According to the latitude and longitude to determine whether the continent
1.1 Determine whether it is in the continental region according to the latitude and longitude
- AMapLocationDataAvailableForCoordinate
/** Determine whether it is in the continental region by latitude and longitude */
+ (BOOL)inChineseMainlandWithCLLocation:(CLLocation *)location regeocode:(AMapLocationReGeocode *)regeocode{
if(AMapLocationDataAvailableForCoordinate(location.coordinate)){// The current location is in the mainland, Hong Kong and Macao
// Hong Kong Special Administrative Region
// Macao Special Administrative Region
///// province/municipality
// @property (nonatomic, copy) NSString *province;
if([regeocode.province isEqualToString:@" Hong Kong Special Administrative Region"] || [regeocode.province isEqualToString:@" Macao Special Administrative Region"]) {return NO;
}else{
return YES; }}else{// Other areas
return NO;
}
return YES;
}
Copy the code
usage
CLLocation *location = [[CLLocation alloc]initWithLatitude:[array.lastObject doubleValue] longitude:[array.firstObject doubleValue]];
AMapLocationReGeocode* regeocode = [AMapLocationReGeocode mj_objectWithKeyValues:geocodesDto.mj_keyValues];
if([ERPAMapLocationTool inChineseMainlandWithCLLocation:location regeocode:regeocode]){
}else{
[SVProgressHUD showInfoWithStatus:@" Your latest location is not supported within the scope!"];
return;
}
[weakSelf locotionRequestLat:[NSNumber numberWithDouble:location.coordinate.latitude].description Lon:[NSNumber numberWithDouble:location.coordinate.longitude].description adress:weakSelf.locationView.adressTextView.text];
Copy the code
1.2 Determine whether the location is located by inverse geocodingLarge _ lu
- Reverse geocoding: converts latitude and longitude into detailed structured addresses, and returns POI and AOI information in the vicinity.
For example: 116.480881,39.989410 Change address description: 6 Futong East Street, Chaoyang District, Beijing
- Through the inverse geocoding to determine whether the processing process is in the mainland
1, request https://restapi.amap.com/v3/geocode/geo the business address location information of user input to the latitude and longitude information
2, according to the obtained latitude and longitude information to determine whether it is in the continent
/** Use inverse geocoding to determine whether it is in the mainland */
- (void)setupGeocode{
__weak __typeof__(self) weakSelf = self;
if (weakSelf.locationView.adressTextView.text.length > 0) {/ / 1, the judge management address information, not to reverse geocoding is empty (request ` https://restapi.amap.com/v3/geocode/geo ` the business address location information of user input to the latitude and longitude information)
[SVProgressHUD showWithStatus:@" Positioning.."];
AFHTTPSessionManager *managers = [AFHTTPSessionManager manager];
managers.requestSerializer = [AFHTTPRequestSerializer serializer];
managers.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html".@"text/plain".@"application/json".@"text/javascript".nil];
/ / please look at the original complete code: https://kunnan.blog.csdn.net/article/details/119685526
}
Copy the code
The complete code quality: kunnan.blog.csdn.net/article/det…
II Modify the location information for test verification
Method 1: Use i4Tools to change the address of the real machine
- With the help of i4Tools
Install command line tools code: xcode - select install since signing command code: codesign - f - s - - the deep/Applications/i4Tools appCopy the code
Method 2: Use the emulator to change the address
- The test data
// type = Hong Kong Special Administrative Region
latitude=22.26429541107516
longitude=114.18135238995905
// type = Macao Special Administrative Region
latitude=22.135584619138957
longitude=113.57214697205735
2020- 04- 09 15:39:54.504424+0800 retail[8369:4238323] reGeocode: AMapLocationReGeocode: {formattedAddress: st. Francis hall area of the Macao special administrative region near the macau youth camp challenge; Country: China; Macao special Administrative Region; city:(null); District: The parish of St. Francis citycode:1853; adcode:820008; street:(null); number:(null); POIName: Macau Youth Challenge Camp; AOIName:(null); }121.524582.25.028822
2020- 04- 09 16:02:47.411507+0800 retail[8369:4238323] reGeocode: AMapLocationReGeocode: {formattedAddress: Taiwan (private) private seven Tian Zhen right brain education nursery; Country: China; Taiwan province c. city:(null); district:(null); citycode:1886; adcode:710000; street:(null); number:(null); POIName:(private) private shita true super right brain education nursery; AOIName:(null); }Copy the code
[for more latitude and longitude data: https://lbs.amap.com/console/show/picker]
Method 3: Use the GPX file to modify the latitude and longitude information
IOS Test tip: Modify the latitude and longitude information in the GPX file (simulate the location of the iOS device)
III. Optimize the processing logic of location permission check
- Optimized the processing logic of location permission check: Mainly for the new “Ask next time” scenario of iOS13 access location information) : Added “Once only” to the App location access in iOS13
Test method: first set [app allowed], then go to the system Settings to modify the location information permission: [ask next time]. Go back to the app and update your location information.
- Before positioning testing authority, if it is kCLAuthorizationStatusNotDetermined, need to implement this method
amapLocationManager:(AMapLocationManager *)manager doRequireLocationAuth:(CLLocationManager*)locationManager
To let the user choose.
- (void)amapLocationManager:(AMapLocationManager *)manager doRequireLocationAuth:(CLLocationManager*)locationManager
{
[locationManager requestAlwaysAuthorization];
}
Copy the code
IV. Disposal of risky merchants
- Risk of refusal of payment
- Suspected fraud, electric fraud, cash risk
- Gambling, abnormal amounts, abnormal tests:
- Cross-border risk
see also
For more content, please pay attention to the official account: iOS Reverse
IOS orientation, the use of geographical/reverse geocoding: https://kunnan.blog.csdn.net/article/details/119685612
Speaking of safety, a word of caution here
Recently, a worm virus incaseFormat will be in January 23 again outbreak, the virus disguised as folder icon, hide their own EXE suffix defrauds users double-click run, attack in the C disk generated ttry.exe or tsay. Exe file, may delete C disk and other system disk outside all drive letter files, great harm.
Even if the virus birth time is long, the existing professional anti-virus software can be reliable. We should also maintain good operation habits: do not download resources from strange websites, do not visit unreliable websites, do not use strange U disks, reduce the frequency of use of mobile storage media.