How can I request permission to post to Facebook from my Swift app?

In my application, I am posting a photo to my code. I also want to post this photo on facebook user wall. The user has already logged into my application with an FB account, but I have not yet requested his permission publish_actions

.

In my application, the user has UISwitch

which, when enabled, is to check if the user has granted permission publish_actions

and if he has not yet requested it from the user.

This is my code:

if !(FBSDKAccessToken.current().hasGranted("publish_actions")) {

    print("Request publish_actions permissions")
    let login: FBSDKLoginManager = FBSDKLoginManager()

    login.logIn(withPublishPermissions: ["publish_actions"], from: self) { (result, error) in
        if (error != nil) {
            print(error!)
        } else if (result?.isCancelled)! {
            print("Canceled")
        } else if (result?.grantedPermissions.contains("publish_actions"))! {
            print("permissions granted")

        }
    }
}else {

}

      

The problem is that when the user picks up the UISwitch, they immediately open Safari to ask them to log into Facebook. When he logs back in, the message "You have already allowed <>" appears. When the user clicks OK

, it goes back to the app and in the console I see Canceled

.

This doesn't seem right to me, so my question is, what's the best way to ask the user to allow this permission?

+3


source to share


1 answer


In some facebook features, you have to submit your facebook viewer app before they can be used. You are trying to get "publish_actions" permission with your facebook account before submitting your app to facebook to watch. In development mode, create a test account from developers.facebook.com to test these features.



0


source







All Articles