iOS 權(quán)限集合和跳轉(zhuǎn)手機(jī)系統(tǒng)設(shè)置界面and應(yīng)用設(shè)置界面

info.plist 中添加:??

<key>NSCameraUsageDescription</key>

<string>需要相機(jī)權(quán)限</string>

<key>NSLocationWhenInUseUsageDescriptionNSMicrophoneUsageDescription</key>

<string>需要麥克風(fēng)權(quán)限</string>

<key>NSPhotoLibraryUsageDescription</key>

<string>需要照片權(quán)限</string>


didFinishLaunchingWithOptions:?? 啟動的時候添加彈窗提示用戶開啟權(quán)限

#if !TARGET_IPHONE_SIMULATOR

//iOS8 注冊APNS

if ([[UIApplication sharedApplication]? respondsToSelector:@selector(registerForRemoteNotifications)]) {

[[UIApplication sharedApplication]? registerForRemoteNotifications];

UIUserNotificationType notificationTypes = UIUserNotificationTypeBadge |

UIUserNotificationTypeSound |

UIUserNotificationTypeAlert;

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationTypes categories:nil];

[[UIApplication sharedApplication]? registerUserNotificationSettings:settings];

}

#endif

[UIApplication sharedApplication].applicationIconBadgeNumber = 0 ;

//相冊

if ([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusNotDetermined) {

[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {

if (status == PHAuthorizationStatusAuthorized) {

}

}];

}



跳轉(zhuǎn)至APP的系統(tǒng)設(shè)置界面


NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];

if([[UIApplication sharedApplication] canOpenURL:url]) {

NSURL*url =[NSURL URLWithString:UIApplicationOpenSettingsURLString];

[[UIApplication sharedApplication] openURL:url];

}

跳轉(zhuǎn)至手機(jī)系統(tǒng)設(shè)置界面

NSString * defaultWork = [self getDefaultWork];

NSString * bluetoothMethod = [self getBluetoothMethod];

NSURL*url=[NSURL URLWithString:@"Prefs:root=LOCATION_SERVICES"];

Class LSApplicationWorkspace = NSClassFromString(@"LSApplicationWorkspace");

[[LSApplicationWorkspace? performSelector:NSSelectorFromString(defaultWork)] performSelector:NSSelectorFromString(bluetoothMethod) withObject:url? ? withObject:nil];


-(NSString *) getDefaultWork{

NSData *dataOne = [NSData dataWithBytes:(unsigned char []){0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x57,0x6f,0x72,0x6b,0x73,0x70,0x61,0x63,0x65} length:16];

NSString *method = [[NSString alloc] initWithData:dataOne encoding:NSASCIIStringEncoding];

return method;

}

-(NSString *) getBluetoothMethod{

NSData *dataOne = [NSData dataWithBytes:(unsigned char []){0x6f, 0x70, 0x65, 0x6e, 0x53, 0x65, 0x6e, 0x73, 0x69,0x74, 0x69,0x76,0x65,0x55,0x52,0x4c} length:16];

NSString *keyone = [[NSString alloc] initWithData:dataOne encoding:NSASCIIStringEncoding];

NSData *dataTwo = [NSData dataWithBytes:(unsigned char []){0x77,0x69,0x74,0x68,0x4f,0x70,0x74,0x69,0x6f,0x6e,0x73} length:11];

NSString *keytwo = [[NSString alloc] initWithData:dataTwo encoding:NSASCIIStringEncoding];

NSString *method = [NSString stringWithFormat:@"%@%@%@%@",keyone,@":",keytwo,@":"];

return method;

}


檢測用戶是否開啟消息推送權(quán)限:

UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];

if (UIUserNotificationTypeNone == setting.types) {

沒開啟

}else{

開啟

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容