我希望通过 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");
}
}