zoukankan      html  css  js  c++  java
  • iOS10 相机相册等权限的使用、检测并引导用户开启权限

    1. <!-- 相册 -->   
    2. <key>NSPhotoLibraryUsageDescription</key>   
    3. <string>App需要您的同意,才能访问相册</string>   
    4. <!-- 相机 -->   
    5. <key>NSCameraUsageDescription</key>   
    6. <string>App需要您的同意,才能访问相机</string>   
    7. <!-- 麦克风 -->   
    8. <key>NSMicrophoneUsageDescription</key>   
    9. <string>App需要您的同意,才能访问麦克风</string>   
    10. <!-- 位置 -->   
    11. <key>NSLocationUsageDescription</key>   
    12. <string>App需要您的同意,才能访问位置</string>   
    13. <!-- 在使用期间访问位置 -->   
    14. <key>NSLocationWhenInUseUsageDescription</key>   
    15. <string>App需要您的同意,才能在使用期间访问位置</string>   
    16. <!-- 始终访问位置 -->   
    17. <key>NSLocationAlwaysUsageDescription</key>   
    18. <string>App需要您的同意,才能始终访问位置</string>   
    19. <!-- 日历 -->   
    20. <key>NSCalendarsUsageDescription</key>   
    21. <string>App需要您的同意,才能访问日历</string>   
    22. <!-- 提醒事项 -->   
    23. <key>NSRemindersUsageDescription</key>   
    24. <string>App需要您的同意,才能访问提醒事项</string>   
    25. <!-- 运动与健身 -->   
    26. <key>NSMotionUsageDescription</key> <string>App需要您的同意,才能访问运动与健身</string>   
    27. <!-- 健康更新 -->   
    28. <key>NSHealthUpdateUsageDescription</key>   
    29. <string>App需要您的同意,才能访问健康更新 </string>   
    30. <!-- 健康分享 -->   
    31. <key>NSHealthShareUsageDescription</key>   
    32. <string>App需要您的同意,才能访问健康分享</string>   
    33. <!-- 蓝牙 -->   
    34. <key>NSBluetoothPeripheralUsageDescription</key>   
    35. <string>App需要您的同意,才能访问蓝牙</string>   
    36. <!-- 媒体资料库 -->   
    37. <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];

            }

     }

  • 相关阅读:
    python socks5 代理服务
    F# 语言参考【摘自MSDN】
    vs2003版本的程序转换为vs2008版本时出现的一些问题及解决办法
    【转】SQL to Mongo Mapping Chart
    jQuery UI Download
    jQuery UI Multiselect
    jqGrid search oper
    apache下用expires_module让浏览器缓存静态文件
    【转】谈谈浏览器的缓存过期时间
    USACO 1.1 Friday the Thirteenth
  • 原文地址:https://www.cnblogs.com/zjoch/p/6133321.html
Copyright © 2011-2022 走看看