3

我希望通过 Facebook 分享我的应用程序。

当我没有配置我的 Facebook 帐户时,我收到以下错误。 当我点击“设置”时,它不起作用。“设置”和“取消”给出相同的结果。

附上错误图片

因此,我导入了 Social.framework。

#import <Social/Social.h>

下面是使用的方法。

-(IBAction) facebookBtnCall{

NSString *facebookTxt = @"Facebook Text";
NSString *AppUrl = @"http://www.google.co.in/";
NSString *ImageUrl = @"http://www.phoolwala.com/adminpanel/uploads/small/1303380733-PHW-B-18-RP-R.jpg";

float version = [[[UIDevice currentDevice] systemVersion] floatValue];

if (version >= 6.0) {

    if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
        SLComposeViewController *fbComposer = [SLComposeViewController
                                               composeViewControllerForServiceType:SLServiceTypeFacebook];
        //set the initial text message
        [fbComposer setInitialText:facebookTxt];
        //add url
        if ([fbComposer addURL:[NSURL URLWithString:AppUrl]]) {
            NSLog(@"Blog url added");
        }

        // you can remove all added URLs as follows
        //[fbComposer removeAllURLs];

        //add image to post
        if ([fbComposer addImage:[UIImage imageNamed:ImageUrl]]) {
            NSLog(@"strong binary added to the post");
        }
        if ([fbComposer addImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:ImageUrl]]]]) {
            NSLog(@"scan is added to the post");
        }

        //remove all added images
        //[fbComposer removeAllImages];

        //present the composer to the user
        [self presentViewController:fbComposer animated:YES completion:nil];

    }
}
else {
    NSLog(@"Load facebook on webview");
}
}
4

1 回答 1

2

您是否尝试过这样做:

    SLComposeViewController *fbController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
    SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){

        [fbController dismissViewControllerAnimated:YES completion:nil];

        switch(result){
            case SLComposeViewControllerResultCancelled:
            default:
            {
                NSLog(@"Cancelled.....");

            }
                break;
            case SLComposeViewControllerResultDone:
            {
                NSLog(@"Posted....");
            }
                break;
        }};

    //[fbController addImage:[UIImage imageNamed:@"1.jpg"]];
    [fbController setInitialText:@"Test message"];
    [fbController addURL:[NSURL URLWithString:self.asset.url]];
    [fbController setCompletionHandler:completionHandler];
    [self presentViewController:fbController animated:YES completion:nil];
} else {
    NSLog(@"no facebook setup");
}
于 2013-01-23T16:27:41.493 回答