• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Swift iOS -UIImagePicker的照片库在模拟器上显示,但在运行Xcode时在实际设备上崩溃(不存在)

用户头像
it1352
帮助1

问题说明

我正在使用Swift 3,iOS 10.3和Xcode 8.3.3.

I'm on Swift 3, iOS 10.3, and Xcode 8.3.3.

当我在模拟器上访问照片库时,UIImagePicker不会出现问题,我可以选择照片. 当我尝试在实际设备(iPhone 7 )上访问照片库时,该应用程序崩溃,因为UIImagePicker无法显示(我什至无法选择一个照片).奇怪的是,在实际的设备上,imagePicker会向您展示相机,而我可以毫无问题地拍照.

When I access the photo library on the simulator the UIImagePicker is presented with no problem and I can pick photos. As soon as I try to access the photo library on an actual device (iPhone 7 ) the app crashes because the UIImagePicker won't get presented (I don't even get to the point to pick a photo). The odd thing is on an actual device the imagePicker presents the camera and I can take photos with no problem.

尽管我没有在问题中添加它,但在我的实际代码中却运行了api权限.在我的实际代码中,我使用了它们并将其注释掉,但问题仍然存在:

Even though I didn't add it inside this question, inside my actual code I have the api permissions running. Inside my actual code I used them and commented them out and the problem still occurs:

import AVFoundation

//there is way more code then this I just put these here to show that I'm using them
PHPhotoLibrary.authorizationStatus()
PHPhotoLibrary.requestAuthorization()
AVCaptureDevice.authorizationStatus(forMediaType: ...)
AVCaptureDevice.requestAccess(forMediaType: ...)

更新:我仍然没有解决该问题,但是我发现了更多信息.我一直在玩这个应用程序,崩溃后我再次尝试了该应用程序,它使我可以访问库.我意识到,只要不运行Xcode,该应用程序就可以让我访问手机上的库.一旦将手机重新插入Xcode并尝试再次访问该库,我就会崩溃.我不知道该怎么做.

UPDATE: I still haven't resolved the issue but I have found out some more information. I kept playing around with the app and I tried the app again after a crash and it let me access the library. What I came to realize is the app will let me access the library on the phone as long as Xcode isn't running. As soon as I plug the phone back into Xcode and try to access the library again I get a crash. I don't know what to make of that.

只要不将Xcode连接到设备上,我就可以成功地从库中获取照片.使用模拟器,我可以轻松获取照片.使用未连接Xcode的设备,我可以获取照片.但是,一旦设备和Xcode连接好,我就会崩溃.我尝试用3种不同的方式(如下所述)初始化UIImagePicker,以查看它们是否会改变结果,但始终相同.我的应用程序有100多个类和50个vcs,也许问题出在其他地方.但是,如果它发生在其他地方,那么当Xcode ISN也没有连接到设备时,它应该会崩溃.

As long as Xcode ISN'T hooked up to the device I can successfully obtain photos from the libary. With the simulator I have no problems obtaining photos. With the device NOT hooked up to Xcode I can obtain photos. However once the device and Xcode are connected I get a crash. I've tried initializing the UIImagePicker 3 different ways (as stated below) to see if either of them would change the outcome but it's always the same. My app as over 100 classes and 50 vcs, maybe the problem is happening somewhere else. However if it was happening somewhere else then it should crash when Xcode ISN'T hooked up to the device either.

在使用UIImagepicker的类中,我注释掉了所有不必要的代码,仅关注库和相机按钮.一旦设备和Xcode纠缠在一起,崩溃总是发生.好处是,一旦他们没有连接,我就可以访问该库,这样用户就不会有问题,因为他们永远不会在我的应用程序中运行Xcode.

Inside the classes that use the UIImagepicker I commented out all the unnecessary code and focused only on the library and camera buttons. The crash always happens once the device and Xcode are intertwined. The good thing is once their not connected I can access the library so the users won't have a problem because they'll never have Xcode running with my app.

应该注意的是,当设备和Xcode挂接在一起时,我可以使用相机并成功拍照.该问题似乎已由图书馆解决.

我已经多次问过这个问题,但答案始终是

I've seen this question asked several times but the answer is always

必须设置info.plist内的权限"

"the permissions inside your info.plist have to be set"

在我的情况下,权限是在info.plist中设置的:

In my situation the permissions are set inside the info.plist:

这是在模拟器的设置"页面内设置为开"的开关"的图片.我无法在实际设备的设置"页面上拍照,但是在那儿,相机"和照片"开关均设置为开"

Here is a pic of the Switch that is set to "on" inside the simulator's Settings page. I couldn't take a photo of the actual device's Setting's page but on there both the Camera and Photos Switches are set to "on"

我的代码:

MyController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate{ 

fileprivate var imagePicker = UIImagePickerController()

override func viewDidLoad() {
        super.viewDidLoad()

        imagePicker.delegate = self
}

@IBAction fileprivate func libraryButton(_ sender: UIButton){

        self.imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
        self.imagePicker.allowsEditing = false
        presentViewController(self.imagePicker, animated: true, completion: nil)
 }

@IBAction fileprivate func cameraButton(_ sender: UIButton){

        self.imagePicker.sourceType = UIImagePickerControllerSourceType.camera
        self.imagePicker.allowsEditing = false
        present(self.imagePicker, animated: true, completion: nil)
 }

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

        if let myImage = info[UIImagePickerControllerOriginalImage] as? UIImage{
            imageView.image = myImage
        }
        else if let myImage = info[UIImagePickerControllerEditedImage] as? UIImage{
            imageView.image = myImage
        }
        else{"UIImagePicker Problem")
        }

        imagePicker.dismiss(animated: true, completion: nil)
    }

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
    imagePicker.dismiss(animated: true, completion: nil)
}
}
}

我也尝试过:

fileprivate var imagePicker:UIImagePickerController?

@IBAction fileprivate func libraryButton(_ sender: UIButton){

        self.imagePicker = UIImagePickerController()
        self.imagePicker?.delegate = self
        self.imagePicker?.sourceType = UIImagePickerControllerSourceType.photoLibrary
        self.imagePicker?.allowsEditing = false
        present(self.imagePicker!, animated: true, completion: nil)
 }

@IBAction fileprivate func cameraButton(_ sender: UIButton){

        self.imagePicker = UIImagePickerController()
        self.imagePicker?.delegate = self
        self.imagePicker?.sourceType = UIImagePickerControllerSourceType.camera
        self.imagePicker?.allowsEditing = false
        present(self.imagePicker!, animated: true, completion: nil)
 }

我也尝试过:

fileprivate let imagePicker:UIImagePickerController?

override func viewDidLoad() {
        super.viewDidLoad()

        imagePicker = UIImagePickerController()
        imagePicker!.delegate = self
}


@IBAction fileprivate func libraryButton(_ sender: UIButton){

        imagePicker!.sourceType = UIImagePickerControllerSourceType.photoLibrary
        imagePicker!.allowsEditing = false
        present(imagePicker!, animated: true, completion: nil)
 }

@IBAction fileprivate func cameraButton(_ sender: UIButton){

        imagePicker!.sourceType = UIImagePickerControllerSourceType.camera
        imagePicker!.allowsEditing = false
        present(imagePicker!, animated: true, completion: nil)
 }

与设备和Xcode连接后,我不断得到的崩溃信息相同:

This is the same crash info I keep getting once the device and Xcode are hooked up:

libc  abi.dylib`__cxa_throw:
->  0x18fd96e70 < 0>:   stp    x22, x21, [sp, #-0x30]!
    0x18fd96e74 < 4>:   stp    x20, x19, [sp, #0x10]
    0x18fd96e78 < 8>:   stp    x29, x30, [sp, #0x20]
    0x18fd96e7c < 12>:  add    x29, sp, #0x20            ; =0x20 
    0x18fd96e80 < 16>:  mov    x19, x2
    0x18fd96e84 < 20>:  mov    x20, x1
    0x18fd96e88 < 24>:  mov    x21, x0
    0x18fd96e8c < 28>:  bl     0x18fd96a88               ; __cxa_get_globals
    0x18fd96e90 < 32>:  mov    x22, x0
    0x18fd96e94 < 36>:  bl     0x18fd9756c               ; std::get_unexpected()
    0x18fd96e98 < 40>:  stur   x0, [x21, #-0x60]
    0x18fd96e9c < 44>:  bl     0x18fd975ac               ; std::get_terminate()
    0x18fd96ea0 < 48>:  stur   x0, [x21, #-0x58]
    0x18fd96ea4 < 52>:  stp    x20, x19, [x21, #-0x70]
    0x18fd96ea8 < 56>:  mov    x8, #0x434c000000000000
    0x18fd96eac < 60>:  movk   x8, #0x4e47, lsl #32
    0x18fd96eb0 < 64>:  movk   x8, #0x432b, lsl #16
    0x18fd96eb4 < 68>:  movk   x8, #0x2b00
    0x18fd96eb8 < 72>:  mov    x19, x21
    0x18fd96ebc < 76>:  str    x8, [x19, #-0x20]!
    0x18fd96ec0 < 80>:  orr    w8, wzr, #0x1
    0x18fd96ec4 < 84>:  stur   x8, [x19, #-0x58]
    0x18fd96ec8 < 88>:  ldr    w8, [x22, #0x8]
    0x18fd96ecc < 92>:  add    w8, w8, #0x1              ; =0x1 
    0x18fd96ed0 < 96>:  str    w8, [x22, #0x8]
    0x18fd96ed4 < 100>: adrp   x8, 0
    0x18fd96ed8 < 104>: add    x8, x8, #0xef8            ; =0xef8 
    0x18fd96edc < 108>: str    x8, [x19, #0x8]
    0x18fd96ee0 < 112>: mov    x0, x19
    0x18fd96ee4 < 116>: bl     0x190433be4               ; _Unwind_RaiseException
    0x18fd96ee8 < 120>: mov    x0, x19
    0x18fd96eec < 124>: bl     0x18fd96f20               ; __cxa_begin_catch
    0x18fd96ef0 < 128>: ldur   x0, [x21, #-0x58]
    0x18fd96ef4 < 132>: bl     0x18fd975c4               ; std::__terminate(void (*)())

我在项目的任何地方都没有Unwind Segue,所以我不确定为什么会这样.但是,无论它是否可以在模拟器上运行,它都应该可以在手机上运行,或者如果它不能在手机上运行,那么它也不应该在模拟器上运行.下面是崩溃报告和堆栈跟踪的代码段.

I don't have an Unwind Segue anywhere in my project so I'm unsure of why it says that. But regardless if it works on the simulator it should work on the phone or if it doesn't work on the phone then it shouldn't work on the simulator either. Below here is a snippet of the crash report and stack trace.

错误报告:

我从设备上删除了该应用程序,关闭了Xcode,重新启动了该应用程序,接受了确定的访问权限,以使其可以访问该库,并且出现了同样的问题.

I deleted the app from the device, shut down Xcode, relaunched it, accepted ok to give it access to the library, and same problem.

有什么问题的想法吗?

正确答案

#1

Ash Furrow帮助我解决了这个问题,因为这是一个非常不明显的问题,并且可能是api错误.我为不熟悉该问题的人员发布了图片.

Ash Furrow helped me out with this as it was a very non obvious problem and possibly an api bug. I posted pics for people unfamiliar with the process to resolve it.

原来是我激活了All ExceptionsBreakpoint Navigator内部.由于某些原因,当我的应用程序连接到Xcode并且UIImagePicker呈现照片库时,触发了All Exceptions断点,并且稍有延迟导致该应用程序崩溃.延迟为毫秒,但足够长的时间使该应用程序认为存在问题.阿什说他以前从未见过这样的东西,并说我的照片库中可能有一张损坏的jpg照片,但那又是一个疯狂的猜测.一种简单的解决方案是停用或删除所有异常"断点,从而解决了该问题.他确实说这可能是一个api问题,因为它仍然导致非常奇怪的崩溃.

It turns out inside the Breakpoint Navigator I had All Exceptions activated. For some reason when my app was hooked up to Xcode and the UIImagePicker was presenting the photo library, the All Exceptions breakpoint was triggered and there was a slight delay that caused the app to crash. The delay was milliseconds but it was long enough that the app thought that there was a problem. Ash said he never saw anything like that before and said there was possibly a corrupted jpg photo in my photo library but then again it was a wild guess. The simple solution was to deactivate or delete the All Exceptions breakpoint and the problem was resolved. He did say it was possibly an api problem because it was still causing a very odd crash.

应该指出的是,他说All Exceptions断点很容易保持激活状态,因为它会早于晚发现异常.我忘记了他的详细解释,但基本上最好还是继续讲下去,如果遇到此问题,只需停用它即可.

It should be noted that he said that All Exceptions break point is good to keep activated because it will find exceptions earlier then later. I forgot his explanation in detail but basically it's best to keep it on and if you run into this problem just deactivate it.

通过停用所有异常断点来解决UIImagePicker库呈现崩溃的步骤:

  1. 在导航窗格的屏幕左侧,看起来像箭头的左侧第7个图标是Breakpoint Navigator
  1. 所有异常断点已激活/突出显示为蓝色

  1. The All Exceptions breakpoint is activated/highlighted to blue

要停用所有例外,请单击突出显示的蓝色箭头或右键单击All Exceptions本身,然后从列表中选择禁用"或删除"

To deactivate the ALL Exceptions either click the highlighted blue arrow or right click on the word All Exceptions itself and from the list either choose Disable or Delete

  1. 假设您选择禁用"或单击蓝色箭头,它将被停用
  1. 很显然,如果您选择Delete(删除),它将从Breakpoint导航器中删除,但是如果您想再次添加它(或者如果您从未开始使用它),那么您仍然必须在Breakpoint Navigator(步骤1)中,然后在窗格的左下角,按加号按钮,然后选择异常断点"将其添加.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfjefg
系列文章
更多 icon
同类精品
更多 icon
继续加载