Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用UIImagePickerController开始/结束外观转换的不平衡调用_Ios_Objective C - Fatal编程技术网

Ios 使用UIImagePickerController开始/结束外观转换的不平衡调用

Ios 使用UIImagePickerController开始/结束外观转换的不平衡调用,ios,objective-c,Ios,Objective C,使用iOS 10+时,有必要添加NSCamerauseCompretation 允许照片加密隐私摄像头使用要求。这会在我第一次启动以下代码时出现一个弹出窗口: 弹出窗口似乎导致了以下错误: 开始/结束外观转换的调用不平衡 这是我试图执行的代码: - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex (NSInteger)buttonIndex{ if (buttonIndex < 2) {

使用iOS 10+时,有必要添加NSCamerauseCompretation 允许照片加密隐私摄像头使用要求。这会在我第一次启动以下代码时出现一个弹出窗口:

弹出窗口似乎导致了以下错误:

开始/结束外观转换的调用不平衡

这是我试图执行的代码:

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

    }
}

我知道这个问题以前被问过很多次。你知道我可能做错了什么吗?提前感谢……

由于iOS 8.3中已弃用了
UIActionSheet
,您必须对所有警报/操作表使用
UIAlertController

请将以下代码用于
操作表

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代理


希望这能有所帮助。

很抱歉问这么长的问题。我尝试了以下操作,但似乎都不起作用:[self.view.window.rootViewController presentViewController:imagePickerController动画:未完成:nil]我还尝试设置[[NSOperationQueue mainQueue]addOperationWithBlock:^{}但似乎总是第一次出现该死的弹出窗口。在你告诉iOS它可以使用摄像头后,错误将不再出现……避免这个问题的明显方法是在显示图像选择器控制器之前让你的应用程序通过整个摄像头/照片库权限舞蹈。Matt我对你的通信不是100%确定ents。当您第一次尝试使用相机时,会出现一个弹出窗口,要求您允许应用程序访问相机,不是吗?有没有其他方法可以允许在没有对话框提示的情况下使用相机?
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];