App Crashed due to Invalid signature for pointer dequeued from free list in UIImagePickerController

孤者浪人 提交于 2019-12-11 00:51:33

问题


I am facing problem in UIImagePickerController selection. When I choose source from Photo Library App crashes due to Invalid signature for pointer dequeued from free list. then If I run again it works fine with the same code. I searched on google and found one question related to my query Xcode - My app crash and the error is "Invalid pointer dequeued from free list *** set a breakpoint in malloc_error_break to debug" .

but solution isn't working in my case.

I am using Xcode 8.1 and my deployment Target is 8.0.


回答1:


As @luke requested for the code for UIImagePickerViewController:

    let pickerView = UIImagePickerController()
    pickerView.delegate = self
    pickerView.allowsEditing = true

    pickerView.sourceType = .photoLibrary

    let authStatus = PHPhotoLibrary.authorizationStatus() // Get the current authorization state.
    // print(authStatus)


    if (authStatus == PHAuthorizationStatus.notDetermined) {

        // Access has not been determined.
        PHPhotoLibrary.requestAuthorization({ (newStatus) in

            if (newStatus == PHAuthorizationStatus.authorized) {
                self.present(pickerView, animated: true, completion: { _ in })

            }

            else {

            }
        })

    } else if authStatus == PHAuthorizationStatus.authorized {
        print("Access has been granted.")

        self.present(pickerView, animated: true, completion: { _ in })

    }  else if (authStatus == PHAuthorizationStatus.denied) {
        print("Access has been denied.")

    }
    else if (authStatus == PHAuthorizationStatus.restricted) {

        print("Restricted access - normally won't happen.")

    }

Now when the user picks a particular image: This method will be called:

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

    //print(info)
    if let pickedImage = info[UIImagePickerControllerEditedImage] as? UIImage {
            YOUR_GLOBAL_IMAGE_VIEW?.contentMode = .scaleAspectFit
            YOUR_GLOBAL_IMAGE_VIEW?.image = pickedImage

        }
    }

    dismiss(animated: true, completion: nil)
}

Don't forget to import PhotosUI and UIImagePickerControllerDelegate.



来源:https://stackoverflow.com/questions/41135701/app-crashed-due-to-invalid-signature-for-pointer-dequeued-from-free-list-in-uiim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!