系统权限
- 在访问相机、相册等,需在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值,如下图:
- 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