App Crashed due to Invalid signature for pointer d

2019-07-18 09:45发布

问题:

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.