我希望通过 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");
}
}
最佳答案
您是否尝试过做这样的事情:
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");
}
关于iphone - 在 iOS6 中通过 Facebook 分享 - 设置按钮不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13030769/