iOS中的权限开启问题

来源:互联网 发布:erp软件开发教程 编辑:程序博客网 时间:2024/06/07 13:00
  1. <!-- 相册 -->  <key>NSPhotoLibraryUsageDescription</key>   <string>App需要您的同意,才能访问相册</string>   
  2. <!-- 相机 -->  <key>NSCameraUsageDescription</key>   <string>App需要您的同意,才能访问相机</string>   
  3. <!-- 麦克风 -->   <key>NSMicrophoneUsageDescription</key>   <string>App需要您的同意,才能访问麦克风</string>   
  4. <!-- 位置 -->   <key>NSLocationUsageDescription</key>   <string>App需要您的同意,才能访问位置</string>   
  5. <!-- 在使用期间访问位置 -->   <key>NSLocationWhenInUseUsageDescription</key>   <string>App需要您的同意,才能在使用期间访问位置</string>   
  6. <!-- 始终访问位置 -->   <key>NSLocationAlwaysUsageDescription</key>   <string>App需要您的同意,才能始终访问位置</string>   
  7. <!-- 日历 -->   <key>NSCalendarsUsageDescription</key>   <string>App需要您的同意,才能访问日历</string>   
  8. <!-- 提醒事项 -->   <key>NSRemindersUsageDescription</key>   <string>App需要您的同意,才能访问提醒事项</string>   
  9. <!-- 运动与健身 -->   <key>NSMotionUsageDescription</key> <string>App需要您的同意,才能访问运动与健身</string>   
  10. <!-- 健康更新 -->   <key>NSHealthUpdateUsageDescription</key>   <string>App需要您的同意,才能访问健康更新 </string>   
  11. <!-- 健康分享 -->   <key>NSHealthShareUsageDescription</key>   <string>App需要您的同意,才能访问健康分享</string>   
  12. <!-- 蓝牙 -->   <key>NSBluetoothPeripheralUsageDescription</key>   <string>App需要您的同意,才能访问蓝牙</string>   
  13. <!-- 媒体资料库 -->   <key>NSAppleMusicUsageDescription</key>  <string>App需要您的同意,才能访问媒体资料库</string>  
info.plist中逐个添加 KEY直接复制   value的string字符串就是提示的文字 可以根据自己需要填写




#import<AVFoundation/AVCaptureDevice.h>

#import <AVFoundation/AVMediaFormat.h>

#import<AssetsLibrary/AssetsLibrary.h>

#import<CoreLocation/CoreLocation.h>


//相机权限

AVAuthorizationStatus authStatus = [AVCaptureDeviceauthorizationStatusForMediaType:AVMediaTypeVideo];

 if (authStatus ==AVAuthorizationStatusRestricted ||//此应用程序没有被授权访问的照片数据。可能是家长控制权限

                authStatus ==AVAuthorizationStatusDenied)  //用户已经明确否认了这一照片数据的应用程序访问

            {

         // 无权限 引导去开启

        NSURL *url = [NSURLURLWithString:UIApplicationOpenSettingsURLString];

        if ([[UIApplicationsharedApplication]canOpenURL:url]) {

            [[UIApplicationsharedApplication]openURL:url];

        }

}


//相册权限

           ALAuthorizationStatus author = [ALAssetsLibraryauthorizationStatus];

           if (author ==kCLAuthorizationStatusRestricted || author ==kCLAuthorizationStatusDenied){

//无权限 引导去开启

        NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];

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

            [[UIApplication sharedApplication] openURL:url];

        }

 }

转载自:
0 0
原创粉丝点击