配置首次應用打開請求用戶授權
- 導入框架MapKit.framework
- 進行授權嗜逻,在info.plist中配置key。這里有兩種授權:
1)NSLocationAlwaysUsageDescription 用戶同意后可永久使用
2)NSLocationWhenInUsageDescription 在用戶打開應用期間使用他挎。
上面這兩種文案在隱私->定位服務->App名字->始終,使用應用期間通過應用說明查看。
應用使用期間欢际,用戶關閉了系統(tǒng)定位类茂,引導用戶開啟系統(tǒng)定位
if (![CLLocationManager locationServicesEnabled]) {
NSLog(@"系統(tǒng)定位未開啟");
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"未開啟" message:@"未開啟定位" preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"去開啟" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
NSURL *url = [NSURL URLWithString:@"App-Prefs:root=Privacy&path=LOCATION"];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
}]];
[alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//
}]];
[self presentViewController:alertController animated:YES completion:nil];
}else {
NSLog(@"系統(tǒng)定位開啟");
}
這時跳轉的界面為:通用-隱私-定位服務
使用應用期間耍属,用戶關閉了該程序的定位服務(設置為永不)
if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorizedAlways) {
NSLog(@"未授權app定位");
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"未授權" message:@"未授權應用定位" preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"去授權" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
}]];
[alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
//
}]];
[self presentViewController:alertController animated:YES completion:nil];
}
點擊確定,跳轉到隱私->定位服務->App名字在這里設置選擇應用使用期間或始終巩检。
下圖為關閉應用定位功能后跳轉
未開啟定位跳轉
下圖為為開啟系統(tǒng)定位后跳轉
關閉應用定位功能跳轉
最后附上跳轉系統(tǒng)相關應用的schema
電池電量 Prefs:root=BATTERY_USAGE
通用設置Prefs:root=General
存儲空間Prefs:root=General&path=STORAGE_ICLOUD_USAGE/DEVICE_STORAGE蜂窩數(shù)據(jù)Prefs:root=MOBILE_DATA_SETTINGS_IDWi-Fi
設置Prefs:root=WIFI
藍牙設置 Prefs:root=Bluetooth
定位設置Prefs:root=Privacy&path=LOCATION
輔助功能Prefs:root=General&path=ACCESSIBILITY
關于手機Prefs:root=General&path=About
鍵盤設置Prefs:root=General&path=Keyboard
顯示設置 Prefs:root=DISPLAY
聲音設置Prefs:root=SoundsApp Store
設置 Prefs:root=STORE
墻紙設置Prefs:root=Wallpaper
打開電話 Mobilephone://
世界時鐘Clock-worldclock:
鬧鐘Clock-alarm://
秒表Clock-stopwatch://
倒計時Clock-timer://
打開相冊Photos://