Ios 应用程序在模拟器中运行良好,但不';t在手机上不能正常工作

Ios 应用程序在模拟器中运行良好,但不';t在手机上不能正常工作,ios,swift,iphone,ocr,Ios,Swift,Iphone,Ocr,我正在Swift for iOS中创建一个OCR应用程序,它需要按下一个按钮(“快照/上传图像”),然后允许用户从照片中选择图像或拍照。这在iPhone11Pro max模拟器中非常有效,但是,在iPhone8模拟器和iPhone8本身上运行时,我会收到错误消息,或者根本不起作用。我已经附上代码和错误 导入UIKit 进口流动储备 导入TesseractOCR 导入GPUImage 类ViewController:UIViewController{ @IBOutlet弱var textView:

我正在Swift for iOS中创建一个OCR应用程序,它需要按下一个按钮(“快照/上传图像”),然后允许用户从照片中选择图像或拍照。这在iPhone11Pro max模拟器中非常有效,但是,在iPhone8模拟器和iPhone8本身上运行时,我会收到错误消息,或者根本不起作用。我已经附上代码和错误

导入UIKit
进口流动储备
导入TesseractOCR
导入GPUImage
类ViewController:UIViewController{
@IBOutlet弱var textView:UITextView!
@IBOutlet弱var活动指示器:UIActivityIndicator视图!
重写func viewDidLoad(){
super.viewDidLoad()
}
//IBAction方法
@IBAction func背景(发件人:任何){
view.endEditing(真)
}
@iAction func拍摄照片(uu发件人:任意){
让imagePickerActionSheet=
UIAlertController(标题:“快照/上载图像”,
信息:无,
preferredStyle:。操作表)
如果UIImagePickerController.IsSourceType可用(.camera){
让cameraButton=UIAlertAction(
标题:“拍照”,
样式:。默认值){(警报)->中的Void
self.activityIndicator.startAnimating()
让imagePicker=UIImagePickerController()
imagePicker.delegate=self
imagePicker.sourceType=.camera
imagePicker.mediaTypes=[kUTTypeImage作为字符串]
自我呈现(imagePicker,动画:真,完成:{
self.activityIndicator.stopAnimating()
})
}
imagePickerActionSheet.addAction(cameraButton)
}
让libraryButton=UIAlertAction(
标题:“选择现有”,
样式:。默认值){(警报)->中的Void
self.activityIndicator.startAnimating()
让imagePicker=UIImagePickerController()
imagePicker.delegate=self
imagePicker.sourceType=.photoLibrary
imagePicker.mediaTypes=[kUTTypeImage作为字符串]
自我呈现(imagePicker,动画:真,完成:{
self.activityIndicator.stopAnimating()
})
}
imagePickerActionSheet.addAction(libraryButton)
let cancelButton=UIAlertAction(标题:“取消”,样式:。取消)
imagePickerActionSheet.addAction(取消按钮)
当前(imagePickerActionSheet,动画:true)
}
//纹理图像识别
func performImageRecognition(image:UIImage){
设scaleImage=image.scaleImage(1000)??image
让prepremedimage=scaledImage.prepremedimage()??scaledImage
如果让tesseract=G8Tesseract(语言:“eng+fra”){
tesseract.engineMode=.tesseractCubeCombined
tesseract.pageSegmentationMode=.auto
tesseract.image=预编辑图像
tesseract.recognize()
textView.text=tesseract.recognizedText
}
activityIndicator.stopAnimating()
}
}
//标记:-UINavigationControllerDelegate
扩展视图控制器:UINavigationControllerDelegate{
}
//标记:-UIImagePickerControllerDelegate
扩展视图控制器:UIImagePickerControllerDelegate{
func imagePickerController(picker:UIImagePickerController,
didFinishPickingMediaWithInfo:[UIImagePickerController.InfoKey:Any]){
卫兵让选定的照片=
信息[原始图像]与其他图像相同{
驳回(动画:真)
回来
}
activityIndicator.startAnimating()
驳回(动画:真){
自我执行图像识别(selectedPhoto)
}
}
}
//标记:-UIImage扩展
扩展UIImage{
func ScaleImage(uMaxDimension:CGFloat)->UIImage{
var scaledSize=CGSize(宽度:maxDimension,高度:maxDimension)
如果size.width>size.height{
scaledSize.height=size.height/size.width*scaledSize.width
}否则{
scaledSize.width=size.width/size.height*scaledSize.height
}
UIGraphicsBeginImageContext(scaledSize)
绘图(in:CGRect(原点:.0,大小:scaledSize))
让ScaleImage=UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsSendImageContext()
返回缩放图像
}
func preprocessedImage()->UIImage{
让stillImageFilter=GPUImageAdaptiveThresholdFilter()
stillImageFilter.blurRadiusInPixels=15.0
let filteredImage=stillImageFilter.image(byFilteringImage:self)
返回过滤器尺寸
}
}
[显示“快照/上载图像”的位置及其限制][1]

当应用程序在iPhone11Max pro模拟器上运行时,它可以工作,但在iPhone8模拟器上运行时,它会出现此错误

[错误][2]

在控制台中:

2019-10-28 17:51:50.440498+0000 Love In A Snap[14813:703702] -[Love_In_A_Snap.ViewController takePhoto:]: unrecognized selector sent to instance 0x7fe503d06d50
2019-10-28 17:51:50.454363+0000 Love In A Snap[14813:703702] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Love_In_A_Snap.ViewController takePhoto:]: unrecognized selector sent to instance 0x7fe503d06d50'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010e63d1ee __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x000000010c275b20 objc_exception_throw + 48
    2   CoreFoundation                      0x000000010e65e154 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   UIKitCore                           0x0000000119832e79 -[UIResponder doesNotRecognizeSelector:] + 302
    4   CoreFoundation                      0x000000010e641f6c ___forwarding___ + 1436
    5   CoreFoundation                      0x000000010e6440f8 _CF_forwarding_prep_0 + 120
    6   UIKitCore                           0x0000000119806082 -[UIApplication sendAction:to:from:forEvent:] + 83
    7   UIKitCore                           0x00000001191ec8e5 -[UIControl sendAction:to:forEvent:] + 223
    8   UIKitCore                           0x00000001191ecc2f -[UIControl _sendActionsForEvents:withEvent:] + 398
    9   UIKitCore                           0x00000001191ebb8e -[UIControl touchesEnded:withEvent:] + 481
    10  UIKitCore                           0x0000000119840a31 -[UIWindow _sendTouchesForEvent:] + 2604
    11  UIKitCore                           0x0000000119842338 -[UIWindow sendEvent:] + 4596
    12  UIKitCore                           0x000000011981d693 -[UIApplication sendEvent:] + 356
    13  UIKitCore                           0x000000011989de5a __dispatchPreprocessedEventFromEventQueue + 6847
    14  UIKitCore                           0x00000001198a0920 __handleEventQueueInternal + 5980
    15  CoreFoundation                      0x000000010e5a0271 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    16  CoreFoundation                      0x000000010e5a019c __CFRunLoopDoSource0 + 76
    17  CoreFoundation                      0x000000010e59f974 __CFRunLoopDoSources0 + 180
    18  CoreFoundation                      0x000000010e59a67f __CFRunLoopRun + 1263
    19  CoreFoundation                      0x000000010e599e66 CFRunLoopRunSpecific + 438
    20  GraphicsServices                    0x000000011055dbb0 GSEventRunModal + 65
    21  UIKitCore                           0x0000000119804dd0 UIApplicationMain + 1621
    22  Love In A Snap                      0x000000010a61132b main + 75
    23  libdyld.dylib                       0x000000010d132d29 start + 1
    24  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

[未来读者摘要:

这是一个
无法识别的选择器
崩溃;由于OP没有提及碰撞或碰撞日志(OP只使用了“什么都没发生”或“不能按按钮”等短语),诊断变得更加困难。但我们最终到达了那里

然而,这是一个稍微不寻常的
无法识别的选择器
,因为Cocoa无法识别的选择器是
[Love_In_a_Snap.ViewController takePhoto:
,我们可以清楚地看到,ViewController确实有这种方法:

 @IBAction func takePhoto(_ sender: Any) {

最后,我们不得不通过假设事情不知何故变得“过时”来解决这个问题。我们删除了故事板中的连接并重新创建。这类事情是固定的,但并非所有情况都如此。然后,我们从设备中删除了应用程序,并清理了DerivedData文件夹,并将其修复。

评论不用于扩展讨论;这段对话已经结束。