1

I want post something on Facebook. I have used SLComposeViewController for that. I just want to ask how can i share if user hasn't configured its app in phone. Is there any way that I open it in browser and then post anything. Consider I want to post any string say "hello there" . So i keep this string , open safari and login there . After I am logged in the string is posted automatically

if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook) {
            let fbShare:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
            fbShare.completionHandler = {
                result in
                switch result {
                case SLComposeViewControllerResult.Cancelled:
                    //Code to deal with it being cancelled
                    break

                case SLComposeViewControllerResult.Done:
                    //Code here to deal with it being completed
                    break
                }
            }
        refrenceViewController.presentViewController(fbShare, animated: true, completion: nil)

    } else {
        //open safari and post it there
    }

1 Answers1

0

I used the following code to post videos to facebook. You can use similar approach to post your text.

NSData *data = [NSData dataWithContentsOfURL:outputFileURL];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                               data, @"video.mp4",
                                               @"video/mp4", @"contentType",
                                               caption, @"description",
                                               nil];
/* make the API call */
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                              initWithGraphPath:@"/me/videos"
                                              parameters:params
                                              HTTPMethod:@"POST"];

[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                                      id result,
                                                      NSError *error) {
       if(!error) {
              DDLogDebug(@"result %@",result);
       } else {
              DDLogError(@"error description : %@",error.description);
              [Helper showToast:[NSString stringWithFormat:@"Unable to share to Facebook : Error: %@",[error localizedDescription]] withDuration:1];
       }
 }];

of course before this you need to make sure that you already have the FBSDKAccess token granted. You can check the full documentation from facebook sdk https://developers.facebook.com/docs/ios/graph

Riandy
  • 372
  • 3
  • 10