ios - 使用 useCameraDevices 交换相机时 iOS 7 崩溃

标签 ios ios7 crash camera

我的应用程序过去在 iOS 6.2 上运行得很好。由于我们更新到 iOS7,当我们更换相机时(我们之前已经做过),它崩溃了。

这是我的代码:

-(void) swapCameras
{
    if (self.cameraDevice == UIImagePickerControllerCameraDeviceRear)
    {
        [self setCameraDevice:UIImagePickerControllerCameraDeviceFront];
    }
    else 
    {
        [self setCameraDevice:UIImagePickerControllerCameraDeviceRear];
    }
}

如果我使用 UIImagePickerControllerCameraDeviceFront 启动相机,它会完美工作。但如果我从 UIImagePickerControllerCameraDeviceRear 开始或尝试在运行时更改它,它会崩溃。

此崩溃是 iOS 7 上的错误吗?其他人也遇到过这种崩溃吗?

提前致谢。

最佳答案

如果有人遇到同样的问题,我通过更新iOS版本找到了解决方案。 这个错误是在我使用iOS 7.0.0时发生的。我将其更新到iOS 7.0.4,它不再崩溃了。苹果可能已在这两个版本之间的任何更新中修复了此错误。

此外,由于此更新不是强制性的,并且某些用户可能没有更新到最新的 iOS 版本,因此我不得不在代码中使用一个技巧来获取当前的 iOS 版本并避免崩溃。我通过使用以下宏来做到这一点:

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice]        systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice]   systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

然后,我在代码中使用它,如下所示:

if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0") && SYSTEM_VERSION_LESS_THAN(@"7.0.4"))
{
    // Do your work to avoid crash
}

关于ios - 使用 useCameraDevices 交换相机时 iOS 7 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20338058/

相关文章:

ios - SwiftUI 和 ScrollView : Views Disappear After Device Rotation

ios - MKPlacemark 上的参数类型错误

ios - inout 参数的外部实例的 Swift 内存地址与复制的实例相同

ios - 触摸 UITextField 时崩溃并显示 "message sent to deallocated instance"

ios - 你如何添加股票苹果 watch 加载屏幕?

ios - 访问从 XIB 实例化的 View subview 的最佳方式?

ios - 分析引擎 : double ON for app

ios - 如何在 iOS 7 中设置 UIBarButtonItem 选中或突出显示的图像或色调颜色?

crash - 在CentOS6.3 x86-64中测试无限递归js时V8崩溃

c - 应用程序崩溃(两个链表的交集)