Photopicker & FB GrapSharer issues in iOS 11

Viewed 1842

My code was working fine on iOS 10 but after updating to iOS 11 nothing seems to work.

This is my code For sharing video on facebook :

internal func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]){
        self.dismiss(animated: true, completion: { () -> Void in

        })
        guard let videoURL = info[UIImagePickerControllerReferenceURL] as? NSURL else {
            return // No video selected.
        }
        print(videoURL)
        let video = Video(url: videoURL as URL)
        var content = VideoShareContent(video: video)
        content.hashtag = Hashtag.init("#Ojas")

        if FBSDKAccessToken.current() != nil{
            if FBSDKAccessToken.current().hasGranted("publish_actions") {
                print("Have permission")
                let sharer = GraphSharer(content: content)
                sharer.failsOnInvalidData = true
                sharer.message = "From #Ojas App"
                sharer.completion = { result in
                    // Handle share results
                    print("Share results : \(result)")
                }

                do{
                    try sharer.share()
                    //try shareDialog.show()
                }catch{
                    print("Facebook share error")
                }

        }

    }

But nothing is working as it was working before. Here is log I see for ImagePicker :

[discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}

And now there is a alert saying "app_name" wants to use "facebook.com" to Sign in. Links I reffered : PhotoPicker discovery error: Error Domain=PlugInKit Code=13

Any idea why everything stopped working for iOS 11. Any help would be appreciated.

1 Answers

Okay, this is about asking permissions which I already asked at the beginning of my app. Still I need to ask again, I dont know why, but it worked.

PHPhotoLibrary.requestAuthorization({ (status: PHAuthorizationStatus) -> Void in
            ()

            if PHPhotoLibrary.authorizationStatus() == PHAuthorizationStatus.authorized {
                print("creating 2")
                // Impelement UiImagepicker method
            }

        })
Related