系統權限
- 在訪問相機、相冊等,需在info.plist里配置上請求權限的描述信息
舉個栗子:
<key>NSCameraUsageDescription</key>
<string>描述信息</string>
下面列出所有的key,用到的自行添加吧。
NSBluetoothPeripheralUsageDescription
NSCalendarsUsageDescription
NSCameraUsageDescription
NSContactsUsageDescription
NSHealthShareUsageDescription
NSHealthUpdateUsageDescription
NSHomeKitUsageDescription
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription
NSMicrophoneUsageDescription
NSMotionUsageDescription
NSPhotoLibraryUsageDescription
NSRemindersUsageDescription
NSSiriUsageDescription
NSSpeechRecognitionUsageDescription
NSVideoSubscriberAccountUsageDescription
NSVoIPUsageDescription
App跳轉設置
openUrl:
openURL: options: completionHandler:
prefs:root=某項服務
若要跳轉系統設置,需先再URL type中添加一個prefs值,如下圖:
設置 url types.png
- iOS <= iOS7 , 只能跳轉到 系統設置頁面
NSURL *url= [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
- iOS >= iOS8 && <= iOS9 ,支持跳轉到設置界面及設置內層界面
可以使用UIApplicationOpenSettingsURLString
跳轉到當前app設置
- iOS >= iOS10,支持跳轉到自己應用設置,不支持跳轉到系統設置
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
UIApplication *application = [UIApplication sharedApplication];
if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
[application openURL:url options:@{} completionHandler:^(BOOL success) {
if (completion) { completion(success); }
}];
}
options可選值:UIApplicationOpenURLOptionUniversalLinksOnly。
Value為布爾值,默認為False,如果Value為True,那么只有安裝了Link所對應的App的情況下才能打開這個Universal Link,而不是通過啟動Safari方式打開這個Link的代表的網站。
[[UIApplication sharedApplication] openURL:URL options:@{UIApplicationOpenURLOptionUniversalLinksOnly:@YES} completionHandler:nil];
- iOS >= iOS8 可以這樣
- (void)openUrl:(NSString *)urlStr completiongHandler:(void (^ __nullable)(BOOL success))completion {
NSURL *url = [NSURL URLWithString:urlStr];
UIApplication *application = [UIApplication sharedApplication];
if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
[application openURL:url options:@{} completionHandler:^(BOOL success) {
if (completion) { completion(success); }
}];
}
else {
BOOL success = false;
if ([application canOpenURL:url]) {
success = [application openURL:url];
}
if (completion) { completion(success); }
}
}
調用
// NSString *urlStr = @"prefs:root=Phone";
NSString *urlStr = UIApplicationOpenSettingsURLString;
[self openUrl:urlStr completiongHandler:^(BOOL success) {
if (!success) {
// 跳轉失敗
}else {
// 跳轉成功
}
}];
- 以下列出一些系統設置的URL
蜂窩網絡:prefs:root=MOBILE_DATA_SETTINGS_ID
VPN — prefs:root=General&path=Network/VPN
Wi-Fi:prefs:root=WIFI
定位服務:prefs:root=LOCATION_SERVICES
個人熱點:prefs:root=INTERNET_TETHERING
關于本機:prefs:root=General&path=About
輔助功能:prefs:root=General&path=ACCESSIBILITY
飛行模式:prefs:root=AIRPLANE_MODE
鎖定:prefs:root=General&path=AUTOLOCK
亮度:prefs:root=Brightness
藍牙:prefs:root=General&path=Bluetooth
時間設置:prefs:root=General&path=DATE_AND_TIME
FaceTime:prefs:root=FACETIME
設置:prefs:root=General
鍵盤設置:prefs:root=General&path=Keyboard
iCloud:prefs:root=CASTLE
iCloud備份:prefs:root=CASTLE&path=STORAGE_AND_BACKUP
語言:prefs:root=General&path=INTERNATIONAL
定位:prefs:root=LOCATION_SERVICES
音樂:prefs:root=MUSIC
Music Equalizer — prefs:root=MUSIC&path=EQ
Music Volume Limit — prefs:root=MUSIC&path=VolumeLimit
Network — prefs:root=General&path=Network
Nike + iPod — prefs:root=NIKE_PLUS_IPOD
Notes — prefs:root=NOTES
Notification — prefs:root=NOTIFICATIONS_ID
Phone — prefs:root=Phone
Photos — prefs:root=Photos
Profile — prefs:root=General&path=ManagedConfigurationList
Reset — prefs:root=General&path=Reset
Safari — prefs:root=Safari
Siri — prefs:root=General&path=Assistant
Sounds — prefs:root=Sounds
Software Update — prefs:root=General&path=SOFTWARE_UPDATE_LINK
Store — prefs:root=STORE
Twitter — prefs:root=TWITTER
Usage — prefs:root=General&path=USAGE
Wallpaper — prefs:root=Wallpaper