gpt4 book ai didi

使用 UIImagePickerController 呈现相机 View 时 iOS 崩溃

转载 作者:行者123 更新时间:2023-12-01 22:35:02 25 4
gpt4 key购买 nike

在 iOS 中,当我使用 UIImagePickerController 呈现相机 View 时,我的应用程序崩溃了。 iOS 8、7 和 iPhone 5s 和 5c 上会出现这种情况。

这是我使用的代码:

UIImagePickerController *imagePickerC = [[UIImagePickerController alloc] init];
imagePickerC.sourceType = type;
imagePickerC.delegate = self;
imagePickerC.allowsEditing = NO;
[self presentViewController:imagePickerC animated:YES completion:nil];

这是崩溃堆栈:

* thread #1: tid = 0x40a07, 0x0000000194bd40a8 libobjc.A.dylib`objc_exception_throw, queue = 'com.apple.main-thread', stop reason = breakpoint 1.2 14.1
frame #0: 0x0000000194bd40a8 libobjc.A.dylib`objc_exception_throw
frame #1: 0x0000000182e3bb34 CoreFoundation`-[__NSArrayI objectAtIndex:] + 224
frame #2: 0x00000001896dbf64 CameraKit`-[CAMFocusView _fadeOutIfNeeded] + 164
frame #3: 0x00000001897394bc CameraKit`-[CAMPreviewView focusDidEnd] + 140
frame #4: 0x00000001897006f4 CameraKit`-[CAMCameraView _updatePreviewForFocusDidEnd] + 44
frame #5: 0x00000001897005b0 CameraKit`-[CAMCameraView cameraControllerFocusDidEnd:] + 32
frame #6: 0x000000018974ed4c CameraKit`-[CAMCaptureController _focusCompleted] + 244
frame #7: 0x0000000189751254 CameraKit`__71-[CAMCaptureController observeValueForKeyPath:ofObject:change:context:]_block_invoke + 956
frame #8: 0x00000001897505e4 CameraKit`-[CAMCaptureController _runOnMainThreadImmediatelyIfPossibleWithBlock:] + 68
frame #9: 0x0000000189750e48 CameraKit`-[CAMCaptureController observeValueForKeyPath:ofObject:change:context:] + 200
frame #10: 0x0000000183da7218 Foundation`-[NSKeyValueObservance observeValueForKeyPath:ofObject:change:context:] + 468
frame #11: 0x0000000183d815c4 Foundation`NSKeyValueNotifyObserver + 340
frame #12: 0x0000000183d810e4 Foundation`NSKeyValueDidChange + 460
frame #13: 0x0000000183d6a88c Foundation`-[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 116
frame #14: 0x000000018179f1f4 AVFoundation`-[AVCaptureFigVideoDevice _handleNotification:payload:] + 900
frame #15: 0x0000000182f1027c CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 20
frame #16: 0x0000000182f0f384 CoreFoundation`__CFRunLoopDoBlocks + 312
frame #17: 0x0000000182f0d9a8 CoreFoundation`__CFRunLoopRun + 1756
frame #18: 0x0000000182e392d4 CoreFoundation`CFRunLoopRunSpecific + 396
frame #19: 0x000000018c8976fc GraphicsServices`GSEventRunModal + 168
frame #20: 0x0000000187a36f40 UIKit`UIApplicationMain + 1488
frame #21: 0x000000010038452c beibei`main(argc=1, argv=0x000000016fd2b9d0) + 248 at main.m:29
frame #22: 0x000000019527ea08 libdyld.dylib`start + 4

所有这些都是系统函数,最后一点是__NSArrayI objectAtIndex

最佳答案

我已经选择了相机图像,下面给出了来源,它对我有用,

if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Device has no camera"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];

[myAlertView show];

}
else
{
UIImagePickerController *photoPicker = [[UIImagePickerController alloc] init];
photoPicker.delegate = self;
photoPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
photoPicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
photoPicker.allowsEditing = YES;
[self presentViewController:photoPicker animated:YES completion:NULL];
}

并且还可以从下面给出的画廊代码中获取图像,它也适合我,

UIImagePickerController *photoPicker = [[UIImagePickerController alloc] init];
photoPicker.delegate = self;
photoPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

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

不要忘记框架 AssetsLibrary(示例 - #import <AssetsLibrary/AssetsLibrary.h> )

希望它有帮助..

关于使用 UIImagePickerController 呈现相机 View 时 iOS 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36440882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com