我想通过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");
}
}
答案 0 :(得分: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");
}