【问题标题】:Native Code Capture Image throws exception on IOS 11?本机代码捕获图像在 IOS 11 上引发异常?
【发布时间】:2019-03-10 00:47:52
【问题描述】:

我对处理打开相机拍照的 Objective-c 代码有疑问,该代码作为本机代码注入代号一内

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            imagePicker = [[UIImagePickerController alloc] init];
            imagePicker.delegate = self;


            imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            NSArray *mediaTypes = [[NSArray alloc]initWithObjects:(NSString *)kUTTypeImage, nil];
            imagePicker.mediaTypes = mediaTypes;
            imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
            [[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:imagePicker animated:YES completion:nil];
        }else{
            [self showAlert:@"No Camera Privilege On This Device"];
        }

问题是当上面的代码在 iOS-11 上执行时,我从 codenameone 得到空指针异常,而不像 iOS-12 那样请求相机权限 代码完美运行

权限在代号设置中添加

codename1.arg.ios.NSPhotoLibraryAddUsageDescription=The App uses the Photo Library to save Images downloaded from News
codename1.arg.ios.NSCameraUsageDescription=The App uses the Camera for Video Chat support
codename1.arg.ios.NSPhotoLibraryUsageDescription=The App uses the Photo Library to save Images downloaded from News

有什么办法可以解决iOS11上的问题

--使用 Xcode9.2 的模拟器的异常堆栈跟踪

2018-10-04 18:47:50.830359+0300 TestApplication[7630:35311] *** Assertion failure in -[UIApplication _cachedSystemAnimationFenceCreatingIfNecessary:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3698.33.6/UIApplication.m:1709
2018-10-04 18:47:50.853277+0300 TestApplication[7630:35311] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'accessing _cachedSystemAnimationFence requires the main thread'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010da7312b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010d107f41 objc_exception_throw + 48
    2   CoreFoundation                      0x000000010da782f2 +[NSException raise:format:arguments:] + 98
    3   Foundation                          0x0000000109d38d69 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
    4   UIKit                               0x0000000107ac692d -[UIApplication _cachedSystemAnimationFenceCreatingIfNecessary:] + 359
    5   UIKit                               0x0000000107b51ac9 +[UIWindow _synchronizeDrawingWithPreCommitHandler:] + 57
    6   UIKit                               0x00000001082cfb7b -[UIInputViewAnimationStyle launchAnimation:afterStarted:completion:forHost:fromCurrentPosition:] + 99
    7   UIKit                               0x000000010872be9a -[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:] + 1697
    8   UIKit                               0x0000000108734c8f __43-[UIInputWindowController setInputViewSet:]_block_invoke.1493 + 97
    9   UIKit                               0x0000000108724208 -[UIInputWindowController performOperations:withTemplateNotificationInfo:] + 46
    10  UIKit                               0x000000010873481b -[UIInputWindowController setInputViewSet:] + 1336
    11  UIKit                               0x000000010872b450 -[UIInputWindowController performOperations:withAnimationStyle:] + 50
    12  UIKit                               0x00000001082c8164 -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 1669
    13  UIKit                               0x00000001082bff4b -[UIPeripheralHost(UIKitInternal) _reloadInputViewsForResponder:] + 2163
    14  UIKit                               0x00000001082c9480 -[UIPeripheralHost(UIKitInternal) _preserveInputViewsWithId:animated:reset:] + 498
    15  UIKit                               0x0000000107c89130 -[UIViewController _presentViewController:modalSourceViewController:presentationController:animationController:interactionController:completion:] + 1233
    16  UIKit                               0x0000000107c8ae94 -[UIViewController _presentViewController:withAnimationController:completion:] + 4621
    17  UIKit                               0x0000000107c8d9a9 __63-[UIViewController _presentViewController:animated:completion:]_block_invoke + 99
    18  UIKit                               0x0000000107c8e079 -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 532
    19  UIKit                               0x0000000107c8d908 -[UIViewController _presentViewController:animated:completion:] + 181
    20  UIKit                               0x0000000107c8dc67 -[UIViewController presentViewController:animated:completion:] + 159

感谢帮助

问候,

【问题讨论】:

  • 请在 Xcode 中添加异常断点,然后在失败的行周围发布代码。问题(隐藏在难以崩溃的输出中)是某个地方(可能在选择器完成后)您的应用程序正在尝试从主线程更新 UI。一旦我们知道问题出在哪里,这很容易解决。
  • @danh 它没有到达图像选择器,基于观察的变量 imagePicker = nil ,这意味着我们没有到达分配发生的行
  • 我给出猜测而不是答案的原因是我不确定您是否发布了最相关的来源。这样做的方法是设置一个异常断点并在触发崩溃的行周围发布上下文
  • @danh ,您输入的相同代码适用于 iOS12 的内容是什么? , 有人可能会认为可能有一些 iOS11 不兼容的 sn-p 代码可能处理转换或呈现图像选择器视图控制器???
  • 我想有两种方法可以调查这个问题:(1)枚举操作系统版本之间的所有更改,并且对于每个更改奇迹,这是否导致我的崩溃?,(2)查看位置代码中的崩溃,调试和修复。如果您需要方法 2 的帮助,请告诉我,我很乐意提供帮助。

标签: ios objective-c codenameone native ios11


【解决方案1】:

感谢您的所有帮助,上述问题仅在 iOS11 上出现,如果我向任何带有动画的视图控制器提供该问题的原因:是的,我通过添加以下代码更改了调用视图控制器的方式

dispatch_queue_t _serialQueue = dispatch_queue_create("x.y.z", DISPATCH_QUEUE_CONCURRENT);
dispatch_sync(_serialQueue, ^{
        self.filePath=param;
        [self showForm];

    });

还有 showForm :只需复制旧的 viewcontroller 并像这样呈现新的 viewcontroller [条件用于等待相机完成拾取并将文件保存到画廊]:

-(void)showForm{
    condition = [[NSCondition alloc] init];
    self.parentViewController = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
    [self.parentViewController.view setUserInteractionEnabled:NO];
    destinationViewController = [[ViewController alloc] initWithValues:self.filePath andCondition:condition andChoice:@"Camera"];
    [[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentViewController:destinationViewController animated:NO completion:nil];
    [condition lock];
    [condition wait];    
    self.filePath = [(ViewController*)destinationViewController getImagePath];
    [self.parentViewController.view setUserInteractionEnabled:YES];
    [condition unlock];



}

希望对有需要的人有所帮助

问候,

【讨论】:

  • 上述方法有效,但导致导航前页面的应用程序动画冻结了一点
猜你喜欢
  • 2012-01-14
  • 2014-02-20
  • 2012-07-17
  • 1970-01-01
  • 2010-09-14
  • 1970-01-01
  • 2014-05-22
  • 2015-09-20
  • 1970-01-01
相关资源
最近更新 更多