For iOS13, when you try to launch the camera from the app, it crashes

On iOS13, a crash occurred when launching the camera and camera roll.

Regarding the camera roll, it was solved by the correspondence described in [Camera Roll], but regarding the camera, it corresponded like [Camera] but it did not move.

Please tell me the measures?

(Sorry for my poor English.)

Replies

Source Code.
Changed to update UI on main thread.

ex)
dispatchsync(dispatchgetmainqueue(),^{
  //UI update process
});

[Camera Roll]
 (IBAction)onTapPhotoLibraryBtn:(id)sender {

    [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {

       
switch (status) {

           
case PHAuthorizationStatusAuthorized: {

                // ユーザーが、アプリが写真のデータへアクセスすることを許可している

                //
PHAssetを取得

                PHFetchResult *allPhotosResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:nil];

                if (allPhotosResult.count == 0) {

                    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@""

                                                                                  
message:@"カメラロールに写真がありません。"

                                                                           
preferredStyle:UIAlertControllerStyleAlert];

                    [alert addAction:[UIAlertAction actionWithTitle:@"OK"

                                                             
style:UIAlertActionStyleDefault

                                                           
handler:nil]];

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

                    return;

                }

                dispatchsync(dispatchgetmainqueue(), ^{                                         //20200713

                imagePickerController = [QBImagePickerController new];

               
imagePickerController.delegate = self;

                imagePickerController.allowsMultipleSelection = YES;

                //   
imagePickerController.maximumNumberOfSelection
= 6;

                imagePickerController.showsNumberOfSelectedAssets = NO;

                //   
imagePickerController.mediaType =
QBImagePickerMediaTypeImage;

                imagePickerController.showsNumberOfSelectedAssets = NO;

                
imagePickerController.assetCollectionSubtypes = @[

                                                                  
@(PHAssetCollectionSubtypeSmartAlbumUserLibrary)

                                                                  
];

                imagePickerController.modalPresentationStyle = UIModalPresentationFullScreen;      //20200713

//               
imagePickerController.modalInPopover = YES;                                       
//20200713

                [self presentViewController:imagePickerController animated:YES completion:NULL];

                    });                                                                            
//20200713

                break;

            }

            case PHAuthorizationStatusRestricted: {

                //
PhotoLibraryへのアクセスが許可されていない時

                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"アプリ使用にはカメラへのアクセス許可が必要になります。iPhoneの「設定」機能から許可設定をおこなってください。" preferredStyle:UIAlertControllerStyleAlert];

                [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

                    // appの設定画面へ遷移

                    NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];

                    [[UIApplication sharedApplication] openURL:settingsURL];

                }]];

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

                break;

            }

            case PHAuthorizationStatusDenied: {

                // ユーザーが明示的に、アプリが写真のデータへアクセスすることを拒否した時

                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"アプリ使用にはカメラへのアクセス許可が必要になります。iPhoneの「設定」機能から許可設定をおこなってください。" preferredStyle:UIAlertControllerStyleAlert];

                [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

                    // appの設定画面へ遷移

                    NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];

                    [[UIApplication sharedApplication] openURL:settingsURL];

                }]];

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

                break;

            }

            default: {

                PHFetchResult *allPhotosResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:nil];

                if (allPhotosResult.count == 0) {

                    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@""

                                                                                  
message:@"カメラロールに写真がありません。"

                                                                           
preferredStyle:UIAlertControllerStyleAlert];

                    [alert addAction:[UIAlertAction actionWithTitle:@"OK"

                                                            
 style:UIAlertActionStyleDefault

                                                           
handler:nil]];

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

                    return;

                }

                break;

            }

        }

    }];

}

[Camera]
  • (void) takePicture {

     // カメラの利用

    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;

    // カメラが利用可能かチェック

    if ([UIImagePickerController isSourceTypeAvailable:sourceType]) {

        dispatch
sync(dispatchgetmainqueue(), ^{                                         //20200713

        // インスタンスの作成

        UIImagePickerController *cameraPicker = [[UIImagePickerController alloc] init];

        // カメラから画像を取り込む設定にする

        cameraPicker.sourceType = sourceType;

        //UIImagePickerControllerDelegate
のデリゲートになる

        cameraPicker.delegate = self;

       

        // 撮影後に写真の編集を行うかどうか

        cameraPicker.allowsEditing = YES;

        //モーダルビューでカメラ起動

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

        });                                                                                
//20200713

    }

    else{

        //
label.text = @"error";

       

        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"シミュレータではカメラは起動できません"

                                                                      
message:@"撮影できません"

                                                               
preferredStyle:UIAlertControllerStyleAlert];

        [alert addAction:[UIAlertAction actionWithTitle:@"OK"

                                                 
style:UIAlertActionStyleDefault

                                               
handler:nil]];

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

        return;

    }

}
The error message is below.

modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread