相機的授權 同樣適用於掃一掃前的授權判斷

int __block tip = 0;

 

    dispatch_semaphore_t sema = dispatch_semaphore_create(0);

    

    [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {

        

        if (!granted) {

            

            tip = 1;

        }

        dispatch_semaphore_signal(sema);

    }];

    

    dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);

    

    if (tip) {

        

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"請在設置->隱私->相機設置本APP訪問權限" delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];

        

        [alert show];

        

    }


//判斷來源是否爲相機   Available 可捕獲的

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

  

        UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera//來源相機

        

        UIImagePickerController *picker = [[UIImagePickerController alloc]init];  //先初始化

        

        picker.delegate = self;

        //判斷是否可以編輯 

        if (edit) {

            picker.allowsEditing = YES; //是否可以編輯

    

        }else{

            picker.allowsEditing = NO;

        }

        

        picker.sourceType = sourceType;  //設置圖片的來源

        

        [self presentViewController:picker animated:YES completion:nil];

   

    }else{

    

       

  UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"請在設置->隱私->相機” 設置本APP訪問權限" delegate:self cancelButtonTitle:@"確定"otherButtonTitles:nilnil];

        

        [alert show];

    }




發佈了24 篇原創文章 · 獲贊 12 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章