iOS10 相機相簿等許可權的使用、檢測並引導使用者開啟許可權

來源:互聯網
上載者:User

標籤:location   str   sap   smo   sage   ons   plist   開啟   string   

  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];

        }

 

 }

 

iOS10 相機相簿等許可權的使用、檢測並引導使用者開啟許可權

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.