在iOS中,当我使用UIImagePickerController呈现相机视图时,我的应用程序崩溃了。这发生在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
。
答案 0 :(得分:0)
我已经选择了相机图像,下面给出了来源,它适用于我,
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>
)
希望它有用......