iOS Swift 3 UIImagePickerController 崩溃

标签 ios swift uiimagepickercontroller xcode8

我将项目升级到 Swift 3,但线路崩溃(在项目中的各个点/viewControllers):

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 中我有:

<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 in Swift 3UIImagePickerController crashes app | Swift3, Xcode8 ),但它不适合我。我做了清理和构建、重新启动 xCode、重新启动 Mac 等。

可能值得指出的是,我的控制台在启动时显示:

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

我的类(class)有代表:

class PersonalSettingsVC: UIViewController, UITextFieldDelegate, UITextViewDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate 

非常感谢任何帮助

最佳答案

好吧,我明白了。 (我生命中的 3 天)即使我将隐私 key 放入我的 info.plist 中,但应用程序实际上并未访问/识别它们。所以我必须去顶级应用程序 ->目标 ->“MY_APP” ->信息并将它们也放在那里。之后,它就跑了。 (Jecky、Seggy 和 KAR 的解决方案很棒,所以我投了赞成票)。显然是一个错误,希望它对某人有帮助。

关于iOS Swift 3 UIImagePickerController 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39995544/

相关文章:

swift - 用于时间序列分析的 Core ML

ios - SwiftUI 将按钮点击发送到 subview

ios - UIImagePickerController allowsEditing=YES 仅用于视频

ios - 加载 UIImagePickerController 更快?

ios - UIWebView 以低质量的放大状态呈现网页

iphone - 如何根据对象的类别汇总获取结果的 number 属性?

ios - 在 iOS 上,如果表格只有 20 或 25 行,是否有办法强制创建 UITableViewCell?

ios - 谁保留 block ?

ios - Swift:为什么我的 iOS 无法扫描其他蓝牙设备

iphone - 如何关闭uiimagePickerController?