gpt4 book ai didi

iOS Swift 3 UIImagePickerController 崩溃

转载 作者:可可西里 更新时间:2023-11-01 00:58:15 25 4
gpt4 key购买 nike

我将项目升级到 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 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com