[英]UIImagePickerController crash only on iOS 7 - iPad
I'm getting hundreds of crashes from one of my live apps ever since people started upgrading to iOS 7. Has anyone else seen this problem? 自从人们开始升级到iOS 7以来,我从我的一个实时应用程序中收到了数百次崩溃。还有其他人看到过这个问题吗? Nothing reproduces on my iPad 3 with iOS 7... 使用iOS 7在iPad 3上无法再现...
Link to Crashlytics: crashes.to/s/edf2e71d9a5 链接到Crashlytics: crashes.to/s/edf2e71d9a5
Fatal Exception CALayerInvalidGeometry
CALayer position contains NaN: [nan nan]
0 ... CoreFoundation __exceptionPreprocess + 130
2 CoreFoundation -[NSException initWithCoder:]
3 QuartzCore CA::Layer::set_position(CA::Vec2<double> const&, bool) + 242
4 QuartzCore -[CALayer setPosition:] + 54
5 QuartzCore -[CALayer setFrame:] + 594
6 UIKit -[UIView(Geometry) setFrame:] + 254
7 UIKit -[UILabel setFrame:] + 138
8 UIKit -[UINavigationItemView initWithNavigationItem:] + 384
9 UIKit -[UINavigationItem _titleView] + 92
10 UIKit -[UINavigationBar _prepareForPushAnimationWithItems:] + 68
11 UIKit -[UINavigationBar pushNavigationItem:] + 292
12 UIKit -[UINavigationBar _pushNavigationItem:transition:] + 386
13 UIKit __71-[UINavigationController pushViewController:transition:forceImmediate:]_block_invoke + 150
14 UIKit -[UINavigationController pushViewController:transition:forceImmediate:] + 1384
15 UIKit -[UINavigationController pushViewController:animated:] + 294
16 UIKit -[UIImagePickerController _setupControllersForCurrentSourceType] + 112
17 UIKit -[UIImagePickerController setSourceType:] + 456
18 ... libdispatch.dylib _dispatch_call_block_and_release + 10
19 libdispatch.dylib _dispatch_client_callout + 22
20 libdispatch.dylib _dispatch_main_queue_callback_4CF$VARIANT$mp + 268
21 CoreFoundation __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
22 CoreFoundation __CFRunLoopRun + 1300
23 CoreFoundation CFRunLoopRunSpecific + 522
24 CoreFoundation CFRunLoopRunInMode + 106
25 GraphicsServices GSEventRunModal + 138
26 UIKit UIApplicationMain + 1136
Collectively we've come to the conclusion that this is a bug in iOS 7 on iPad. 总的来说,我们得出结论,这是iPad上的iOS 7中的一个错误。 It occurs when you attempt to show a UIImagePickerController in a UIPopoverControl from a UIBarButtonItem for the first time. 当您第一次尝试从UIBarButtonItem在UIPopoverControl中显示UIImagePickerController时,会发生这种情况。 After the user grants permission to their photo album the crash happens. 在用户授予其相册的许可后,崩溃就会发生。 It appears the solution for now is to request permission to photos before opening the UIPopoverControl. 现在的解决方案似乎是在打开UIPopoverControl之前请求照片权限。 Here is how I implemented my solution: 以下是我实施解决方案的方法:
// Photo Library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
void(^blk)() = ^() {
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if (NIIsPad()) {
UIPopoverController* popover = [[UIPopoverController alloc] initWithContentViewController:picker];
[popover presentPopoverFromBarButtonItem:self.popoverAnchor permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
[self.navigationController presentModalViewController:picker animated:YES];
}
};
// Make sure we have permission, otherwise request it first
ALAssetsLibrary* assetsLibrary = [[ALAssetsLibrary alloc] init];
ALAuthorizationStatus authStatus;
if (IOS_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0"))
authStatus = [ALAssetsLibrary authorizationStatus];
else
authStatus = ALAuthorizationStatusAuthorized;
if (authStatus == ALAuthorizationStatusAuthorized) {
blk();
} else if (authStatus == ALAuthorizationStatusDenied || authStatus == ALAuthorizationStatusRestricted) {
[[UIAlertView alertViewWithTitle:@"Grant photos permission" message:@"Grant permission to your photos. Go to Settings App > Privacy > Photos."] show];
} else if (authStatus == ALAuthorizationStatusNotDetermined) {
[assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
// Catch the final iteration, ignore the rest
if (group == nil)
dispatch_async(dispatch_get_main_queue(), ^{
blk();
});
*stop = YES;
} failureBlock:^(NSError *error) {
// failure :(
dispatch_async(dispatch_get_main_queue(), ^{
[[UIAlertView alertViewWithTitle:@"Grant photos permission" message:@"Grant permission to your photos. Go to Settings App > Privacy > Photos."] show];
});
}];
}
}
Don't forget to add AssetsLibrary.framework to your project. 不要忘记将AssetsLibrary.framework添加到您的项目中。
I was having the same issue. 我遇到了同样的问题。
I had a UIImagePickerController
displayed inside a UIPopoverController
with the size defined by UIImagePickerController's contentSizeForViewInPopover function. 我在UIPopoverController
显示了一个UIImagePickerController
,其大小由UIImagePickerController的contentSizeForViewInPopover函数定义。
To fix this issue I changed UIPopoverController
size to UIImagePickerController's preferredContentSize
function. 为了解决这个问题,我将UIPopoverController
大小更改为UIImagePickerController's preferredContentSize
函数。
您可以使用自定义框架并加载弹出窗口,如下所示
[popOver presentPopoverFromRect:CGRectMake(self.view.frame.size.width-50, 50, 10, 10) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.