问题描述
我将项目升级到 Swift 3 并且我在线上崩溃了(在项目中的各个点/viewControllers):
I upgraded project to Swift 3 and I am getting a crash on the line (at various points/viewControllers in the project) :
present(picker, animated: true, completion: nil)
在函数中:
@IBAction func userImage(_ sender: AnyObject){
print("button pressed")
let picker = UIImagePickerController()
picker.delegate = self
picker.allowsEditing = false
picker.sourceType = .photoLibrary
present(picker, animated: true, completion: nil) // -> crashes here
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
self.imageToPost.setImage(newImage, for: UIControlState())
self.imageToPost.imageView?.contentMode = UIViewContentMode.scaleAspectFill
picker.dismiss(animated: true, completion: nil)
}
控制台中的崩溃消息:
libsystem_kernel.dylib`__abort_with_payload:
0x11108d138 <+0>: movl $0x2000209, %eax ; imm = 0x2000209
0x11108d13d <+5>: movq %rcx, %r10
0x11108d140 <+8>: syscall
-> 0x11108d142 <+10>: jae 0x11108d14c ; <+20>
0x11108d144 <+12>: movq %rax, %rdi
0x11108d147 <+15>: jmp 0x111086d6f ; cerror_nocancel
0x11108d14c <+20>: retq
0x11108d14d <+21>: nop
0x11108d14e <+22>: nop
0x11108d14f <+23>: nop
在我的 info.plist 中,我有:
in my in info.plist I have:
<key>NSPhotoLibraryUsageDescription</key>
<string>$(PRODUCT_NAME) photo gallery use</string>
<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) camera use </string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) microphone use</string>
我环顾四周,确实看到在 info.plist 中有 NSPhotoLibraryUsageDescription 和 NSCameraUsageDescription 解决了这个问题(UIImagePickerController 在Swift 3 和 UIImagePickerController 崩溃应用程序 | Swift3, Xcode8),但它不适合我.我做了清理和构建,重新启动了 xCode,重新启动了 Mac 等.
I looked around and did see that having NSPhotoLibraryUsageDescription and NSCameraUsageDescription in info.plist solves the issue (UIImagePickerController in Swift 3 and UIImagePickerController crashes app | Swift3, Xcode8), but it doesn't for me. I did clean and build, restarted xCode, restarted Mac, etc.
值得指出的是,我的控制台在启动时说:
It might be worth pointing out that my console at startup says:
objc[11204]: Class PLBuildVersion is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x11a0d8910) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x119f02210). One of the two will be used. Which one is undefined.
但根据这个线程无关紧要https://forums.developer.apple.com/thread/63254
but according to this thread that doesn't matter https://forums.developer.apple.com/thread/63254
我的班级有代表:
class PersonalSettingsVC: UIViewController, UITextFieldDelegate, UITextViewDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate
非常感谢任何帮助
推荐答案
好的,我想通了.(我生命中的 3 天)即使我将隐私密钥放在我的 info.plist 中,它们实际上并没有被应用程序访问/识别.所以我不得不去顶级应用程序 -> 目标 -> "MY_APP" -> 信息并将它们也放在那里.在那之后,它跑了.(来自 Jecky、Seggy 和 KAR 的解决方案很棒,所以我投了赞成票).显然是一个错误,希望对某人有所帮助.
Ok, so I figured it out. (3 days of my life) Even though I put the Privacy keys in my info.plist, they were not actually accessed/ recognised by the app. so I had to go top level app -> Targets -> "MY_APP" -> info and put them there as well. after that, it ran. (Solutions from Jecky, Seggy and KAR were great, so I upvoted). obviously a bug, hope it helps someone.
这篇关于iOS Swift 3 UIImagePickerController 崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!