2014-11-03 95 views
1

我是编程新手。我将用Apple新编程语言Swift学习iOS应用程序开发。 而我按照这个网站(https://developer.apple.com/swift/blog/?id=16)开始。
我将视频中的代码复制到我的Xcode项目中。当我在iOS 8.1 iOS模拟器中运行应用程序时,任何事情都很好。
但我在选择iOS 7.1 iOS模拟器时出现异常。
而我把应用程序放到我的iPhone 5S(iOS 7.1.2)中,它被破坏。libC++ abi.dylib:以iOS 7.1上的NSException类型的未捕获异常终止

下面是我从视频复制代码:

import UIKit 
class ViewController: UIViewController { 
    @IBOutlet weak var photoImageView: UIImageView! 
    let context = CIContext(options: nil) 

    @IBAction func applyFilter(sender: AnyObject) { 
     let inputImage = CIImage(image: photoImageView.image) 

     let randomColor = [kCIInputAngleKey: (Double(arc4random_uniform(314))/100)] 
     let filteredImage = inputImage.imageByApplyingFilter("CIHueAdjust",withInputParameters: randomColor) 
     let renderedImage = context.createCGImage(filteredImage, fromRect: filteredImage.extent()) 

     photoImageView.image = UIImage(CGImage: renderedImage) 
    } 

    override func viewDidLoad() { 
     super.viewDidLoad() 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
    } 
} 

以下是我从控制台得到:

2014-11-03 16:17:30.645 njnj[2748:60b] -[CIImage imageByApplyingFilter:withInputParameters:]: unrecognized selector sent to instance 0x7fe4e3d165e0 
2014-11-03 16:17:30.649 njnj[2748:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CIImage imageByApplyingFilter:withInputParameters:]: unrecognized selector sent to instance 0x7fe4e3d165e0' 
*** First throw call stack: 
(
    0 CoreFoundation      0x0000000106c8b495 __exceptionPreprocess + 165 
    1 libobjc.A.dylib      0x000000010852799e objc_exception_throw + 43 
    2 CoreFoundation      0x0000000106d1c65d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 
    3 CoreFoundation      0x0000000106c7cd8d ___forwarding___ + 973 
    4 CoreFoundation      0x0000000106c7c938 _CF_forwarding_prep_0 + 120 
    5 njnj        0x0000000106b934a0 _TFC4njnj14ViewController11applyFilterfS0_FPSs9AnyObject_T_ + 3648 
    6 njnj        0x0000000106b93a66 _TToFC4njnj14ViewController11applyFilterfS0_FPSs9AnyObject_T_ + 54 
    7 UIKit        0x000000010753af06 -[UIApplication sendAction:to:from:forEvent:] + 80 
    8 UIKit        0x000000010753af06 -[UIApplication sendAction:to:from:forEvent:] + 80 
    9 UIKit        0x000000010753aeb4 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17 
    10 UIKit        0x0000000107617880 -[UIControl _sendActionsForEvents:withEvent:] + 203 
    11 UIKit        0x0000000107616dc0 -[UIControl touchesEnded:withEvent:] + 530 
    12 UIKit        0x0000000107571d05 -[UIWindow _sendTouchesForEvent:] + 701 
    13 UIKit        0x00000001075726e4 -[UIWindow sendEvent:] + 925 
    14 UIKit        0x000000010754a29a -[UIApplication sendEvent:] + 211 
    15 UIKit        0x0000000107537aed _UIApplicationHandleEventQueue + 9579 
    16 CoreFoundation      0x0000000106c1ad21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
    17 CoreFoundation      0x0000000106c1a5f2 __CFRunLoopDoSources0 + 242 
    18 CoreFoundation      0x0000000106c3646f __CFRunLoopRun + 767 
    19 CoreFoundation      0x0000000106c35d83 CFRunLoopRunSpecific + 467 
    20 GraphicsServices     0x000000010baf2f04 GSEventRunModal + 161 
    21 UIKit        0x0000000107539e33 UIApplicationMain + 1010 
    22 njnj        0x0000000106b9582e top_level_code + 78 
    23 njnj        0x0000000106b9586a main + 42 
    24 libdyld.dylib      0x0000000108ee55fd start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 

我希望有人能帮助我解决这个问题。

+0

崩溃日志抱怨'imageByApplyingFilter:withInputParameters:'。您是否在文档中查找了该功能?根据https://developer.apple.com/library/ios/releasenotes/General/iOS80APIDiffs/frameworks/CoreImage.html,它在*** 8.0中增加了***。 – 2014-11-03 09:07:38

+0

@MartinR,非常感谢。我只是谷歌的“imageByApplyingFilter iOS 7.1”,但我没有发现我需要的东西。非常感谢你。 – 2014-11-03 09:12:43

+0

为什么不确定你的应用程序的'Deployment Target'适合你希望你的应用运行的设备/模拟器的版本? – findall 2014-11-03 11:12:40

回答

0

通常“无法识别的选择器发送到实例”(由-doesNotRecognizeSelector产生)表示内存管理问题,通常是仍然引用某处的对象的过度释放。

我建议你运行带内存调试的调试版本来分类你的应用程序的内存问题。我建议你通过最新版本的Xcode使用ASan。如果这不是一个选项,你可以使用malloc历史跟守卫malloc,scribble和NSZombies。

+0

僵尸有助于调试BAD_ACCESS。无法识别的选择器意味着找不到您要调用的方法的签名。在Xcode中这是一个奇怪的事情,当二进制文件(如.framework)未链接,嵌入或复制时,运行时会显示此错误。特别是当该方法属于一个类别时。 – 2016-09-17 21:54:50

+0

僵尸有助于调试导致BAD_ACCESS的过度版本,因为它保持活动的对象来捕获这些访问。它还有助于调试导致-doesNotRecognizeSelector:的过度版本。当一个对象被释放(仍然存在引用)时,可以在该地址创建另一个对象,然后通过对释放对象的引用进行未来访问将触发-doesNotRecognizeSelector :. – 2016-09-18 17:16:25

+0

我同意你的答案。你有一个或两个示例程序来演示这两种类型的僵尸吗?或者也许是一个教程的链接?谢谢 – 2016-09-23 03:53:17

相关问题