我是編程新手。我將用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)
我希望有人能幫助我解決這個問題。
崩潰日誌抱怨'imageByApplyingFilter:withInputParameters:'。您是否在文檔中查找了該功能?根據https://developer.apple.com/library/ios/releasenotes/General/iOS80APIDiffs/frameworks/CoreImage.html,它在*** 8.0中增加了***。 – 2014-11-03 09:07:38
@MartinR,非常感謝。我只是谷歌的「imageByApplyingFilter iOS 7.1」,但我沒有發現我需要的東西。非常感謝你。 – 2014-11-03 09:12:43
爲什麼不確定你的應用程序的'Deployment Target'適合你希望你的應用運行的設備/模擬器的版本? – findall 2014-11-03 11:12:40