ios7及以後系統關於新增相機對應用的隱私授權判斷問題


問題來源: ios7及以後的系統自帶二維碼掃描庫AVFoundation,但是若關閉相機對應用的隱私授權後,二維碼掃描會造成應用閃退;

此時,需針對用戶是否開相機隱私授權做相關判斷;

[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];

  [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];

以上兩個方法均無法實現判斷,返回值均爲yes,只能作爲iPhone/ipod 是否有相機功能判斷;


具體解決方法如下:

if(isIOS7Later)   //isIOS7Later 是用來區分ios7及以後的系統;

    {

        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];

        if (authStatus != AVAuthorizationStatusAuthorized)

        {

//此處可以做相關提示及操作;

            UIAlertView * tip = [[UIAlertView alloc] initWithTitle:@"溫馨提示" message:@"您相機隱私授權尚未打開,若要打開請前往 設置-隱私-相機 中打開。" delegate:self cancelButtonTitle:nil otherButtonTitles:@"確定", nil];

            [tip show];

            [tip release];

            return;

        }

    }



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章