2017-01-19 7 views
0

NSCameraUsageDescriptionを追加するためにiOS 10+が必要です 暗号化のための写真を許可するプライバシーカメラ使用要件。UIImagePickerControllerを使用して外観トランジションを開始/終了するための不均衡な呼び出し

ポップアップはそれはそう、次のエラーの原因となっている:

アンバランスコール用/終了外観遷移を開始するにはこれは私が次のコードを最初に起動したときに表示されるようにポップアップの原因となります。

これは私が実行しようとしているコードです:できるだけ早く私はアプリは、それがクラッシュしたカメラを使用できるようにするまでのポップで[OK]を選択すると

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex (NSInteger)buttonIndex{ 
    if (buttonIndex < 2) { 

     UIImagePickerController *imagePickerController[[UIImagePickerController alloc] init]; 

     imagePickerController.mediaTypes = @[(__bridge NSString *)kUTTypeImage]; 

     imagePickerController.allowsEditing = YES; 

     imagePickerController.delegate = self; 

     if (buttonIndex == 0) {   
      imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; 

     } else if (buttonIndex == 1) { 
      imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 

     } 

     [self presentViewController:imagePickerController animated:NO completion:nil]; 

    } 
} 

ポップアップが表示されないため、アプリに戻ってもう一度やり直すと、コードが実行され、それに応じて画像を取得できます。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ 


    NSString *tmpFilePath = @""; 
    tmpFilePath = [_myHelper retrieveAppDirectory:self.username]; 


    UIImage *image = [info objectForKey: UIImagePickerControllerEditedImage]; 


    if (!image) { 

     [info objectForKey: UIImagePickerControllerOriginalImage]; 
    } 


    NSString *imageName = [NSString stringWithFormat:@"image-%d.securedData", self.photos.count + 1]; 


    [_myHelper performEncryptionForSecuredData:image filePath:tmpFilePath fileName:imageName]; 


    [self.photos addObject:image]; 

    [self.collectionView reloadData]; 

    [picker dismissViewControllerAnimated:YES completion:nil]; 
} 

これまでに何度も聞いたことがあります。私はおそらく間違って何を考えている?事前のおかげで....... UIActionSheetとして

+0

このような長い質問に申し訳ありません。私は次のことを試みたが、どれも動作するように見えるない: [self.view.window.rootViewController presentViewController:imagePickerControllerアニメーション:NO完了:なし]:^ { } Iはまた、[[NSOperationQueue mainQueue] addOperationWithBlockを設定しようとしたん しかし、それはいつも初めてポップアップ表示されるようです。あなたがiOSにカメラを使うことができたら、エラーはもう現れません..... –

+0

この問題を避けるための明白な方法は、カメラ/写真ライブラリの許可全体を通してアプリケーションを取得することです。 。 – matt

+0

マット私はあなたのコメントに100%確信していません。あなたがカメラにアクセスすることを許可するように促すポップアップは、初めてカメラを使用しようとするときに発生しますか?ダイアログプロンプトなしでカメラの使用を許可する別の方法はありますか? –

答えて

0

は、すべてのアラート/ ActionSheetためUIAlertControllerを使用しなければならないのiOS 8.3から廃止されました。

ActionSheetためのコードの下に使用してください:

UIAlertController* alert = [UIAlertController 
           alertControllerWithTitle:nil  // Must be "nil", otherwise a blank title area will appear above our two buttons 
           message:nil 
           preferredStyle:UIAlertControllerStyleActionSheet]; 

UIAlertAction* button0 = [UIAlertAction 
           actionWithTitle:@"Cancel" 
           style:UIAlertActionStyleCancel 
           handler:^(UIAlertAction * action) 
           { 
            // UIAlertController will automatically dismiss the view 
           }]; 

UIAlertAction* button1 = [UIAlertAction 
           actionWithTitle:@"Camera" 
           style:UIAlertActionStyleDestructive 
           handler:^(UIAlertAction * action) 
           { 
            // The user tapped on "Camera" 
            UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; 

            imagePickerController.allowsEditing = YES; 
            imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; 
            imagePickerController.delegate = self; 
            [self presentViewController:imagePickerController animated:NO completion:nil]; 
           }]; 

UIAlertAction* button2 = [UIAlertAction 
           actionWithTitle:@"Photo Library" 
           style:UIAlertActionStyleDestructive 
           handler:^(UIAlertAction * action) 
           { 
            // The user tapped on "Camera" 
            UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; 

            imagePickerController.allowsEditing = YES; 
            imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
            imagePickerController.delegate = self; 
            [self presentViewController:imagePickerController animated:NO completion:nil]; 
           }]; 
    [alert addAction:button0]; 
    [alert addAction:button1]; 
    [alert addAction:button2]; 
    [self presentViewController:alert animated:YES completion:nil]; 

は、あなたと同じImagepickerデリゲートを使用してください。

これが役に立ちます。

関連する問題