iOS 手机权限设置

在plist里面添加即可:

Privacy - Microphone Usage Description //麦克风权限
Privacy - Contacts Usage Description   //通讯录权限
Privacy - Camera Usage Description     //摄像头权限
Privacy - NSSiriUsageDescription       //Siri的权限
Privacy - Bluetooth Peripheral Usage Description //蓝牙
Privacy - Reminders Usage Description  //提醒事项
Privacy - Motion Usage Description     //运动与健康
Privacy - Media Libaray Usage Description //媒体资源库
Privacy - Photo Libaray Usage Description //相册
Privacy - Photo Library Additions Usage Description   //保存图片到相册(iOS 11)
Privacy - Calendars Usage Description  //日历

//相机权限:
Key:Privacy - Camera Usage Description
Value:允许此权限才能使用相机功能

//相册:
Key:Privacy - Photo Library Usage Description
Value:允许此权限才能保存图片

//麦克风:
Key:Privacy - Microphone Usage Description
Value:允许此权限才能录音

//位置权限:
Key:Privacy - Location Usage Description
Value:允许此权限才能启用:定位功能

Key:Privacy - Location When In Use Usage Description
Value:允许此权限才能在应用运行期间启用:定位功能

Key:Privacy - Location Always Usage Description
Value:允许此权限才能一直启用:定位功能

//日历权限:
Key:Privacy - Calendars Usage Description
Value:允许此权限才能访问:日历

//提醒事项:
Key:Privacy - Reminders Usage Description
Value:允许此权限才能访问:提醒事项

// 运动与健康:
Key:Privacy - Motion Usage Description
Value:允许此权限才能访问:运动与健康

Key:Privacy - Health Update Usage Description
Value:允许此权限才能访问:健康更新

Key:Privacy - Health Share Usage Description
Value:允许此权限才能访问:健康数据分享

//蓝牙权限:
Key:Privacy - Bluetooth Peripheral Usage Description
Value:允许此权限才能访问:蓝牙

//媒体资料库:
Key:Privacy - Media Library Usage Description
Value:允许此权限才能访问:媒体资料库

当权限为AuthorizationStatusNotDetermined状态时,用户还没用做出选择,弹出系统的权限框的方法

相册、照片

#import 
// 判断授权状态
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status == PHAuthorizationStatusRestricted) { // 此应用程序没有被授权访问的照片数据。可能是家长控制权限。         
    NSLog(@"因为系统原因, 无法访问相册");
} else if (status == PHAuthorizationStatusDenied) { // 用户拒绝访问相册
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"警告" message:@"请去-> [设置 - 隐私 - 相机 - 摩宝网] 打开访问开关" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"去设置", nil];
    [alertView show];
} else if (status == PHAuthorizationStatusAuthorized) { // 用户允许访问相册
    // 放一些使用相册的代码
    UIImageWriteToSavedPhotosAlbum(codeImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
} else if (status == PHAuthorizationStatusNotDetermined) { // 用户还没有做出选择
    // 弹框请求用户授权
    [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
        if (status == PHAuthorizationStatusAuthorized) { // 用户点击了好
          // 放一些使用相册的代码
          UIImageWriteToSavedPhotosAlbum(codeImage, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
        }
    }];
}

//指定回调方法
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    if(!error){
        [MBProgressHUD showSuccess:@"二维码保存成功!" toView:self];
    }
}

媒体库

#import 
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_3
MPMediaLibraryAuthorizationStatus authStatus = [MPMediaLibrary authorizationStatus];
if (authStatus == MPMediaLibraryAuthorizationStatusNotDetermined) {
    [MPMediaLibrary requestAuthorization:^(MPMediaLibraryAuthorizationStatus status) {
        if (status == MPMediaLibraryAuthorizationStatusAuthorized) {
                  //do something
         }  
} else if (authStatus == MPMediaLibraryAuthorizationStatusAuthorized){

}
#endif

打包上传App Store的时候,有时候会出现无效的二进制文件,这有可能是应为用了蓝牙等的API,没有在plist里面添加权限设置。

慢慢来,一步一个巴掌印。。。。。

你可能感兴趣的:(iOS 手机权限设置)