1

我想在 Facebook 上发布一些东西。我已经习惯SLComposeViewController了。我只想问如果用户尚未在手机中配置其应用程序,我该如何分享。有什么方法可以在浏览器中打开它然后发布任何内容。考虑我想发布任何字符串说 "hello there" 。所以我保留这个字符串,打开 safari 并在那里登录。在我登录后,字符串会自动发布

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
    }
4

1 回答 1

0

我使用以下代码将视频发布到 Facebook。您可以使用类似的方法来发布您的文本。

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];
       }
 }];

当然,在此之前,您需要确保您已经获得了 FBSDKAccess 令牌。您可以从 facebook sdk https://developers.facebook.com/docs/ios/graph查看完整文档

于 2016-05-06T10:07:34.557 回答