我想将图片发布到脸书和推特上。我很喜欢推特,但没有使用SLComposeViewController类的facebook。随着添加图像,我能够将文本和网址发布到Facebook。问题是,当我使用添加图像我无法发布此图像和文本,网址。 SLComposeViewController在我发送时显示图像,文本和URL。我有正确的appId,我没有得到任何错误。但问题仍然存在。我不是问题所在。请帮帮我。
- (void)performFBRequestUploadForImage{
[self showListOfFaceBookAccountsFromStore];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
NSString *output;
switch (result) {
case SLComposeViewControllerResultCancelled:
output = @"ACtionCancelled";
break;
case SLComposeViewControllerResultDone:
output = @"Post Successfull";
[self dismissViewControllerAnimated:YES completion:nil];
break;
default:
break;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Face Book Message" message:output delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
};
[mySLComposerSheet addImage:[UIImage imageNamed:@"images4.jpg"]];
[mySLComposerSheet setInitialText:@"I am developer."];
[mySLComposerSheet addURL:[NSURL URLWithString:@"http://stackoverflow.com/"]];
[mySLComposerSheet setCompletionHandler:completionHandler];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}
}
- (void)showListOfFaceBookAccountsFromStore
{
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
if( [SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook] )
{
NSDictionary *options = @{
@"ACFacebookAppIdKey" : myAppId,
@"ACFacebookPermissionsKey" : @[@"publish_stream"],
@"ACFacebookAudienceKey" : ACFacebookAudienceFriends};
[accountStore requestAccessToAccountsWithType:accountType options:options completion:^(BOOL granted, NSError *error){
if(granted) {
ACAccount * account = [[accountStore accountsWithAccountType:accountType] lastObject];
NSLog(@"Facebook user: %@",[account username]);
if([account username]==NULL){
[self facebookAlert];
} else {
}
}
else{
NSLog(@"Read permission error: %@", [error localizedDescription]);
}
}];
} else {
[self facebookAlert];
}
}
答案 0 :(得分:2)
我在我的项目中使用了以下代码来发布图像,它可以正常工作。
if([SLComposeViewController instanceMethodForSelector:@selector(isAvailableForServiceType)] != nil)
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
NSLog(@"Cancelled");
} else
{
NSLog(@"Done");
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
[controller setInitialText:@"Check out my Christmas Gift!"];
[controller addImage:@"gift.jpg"];
[self presentViewController:controller animated:YES completion:Nil];
}
您只需尝试按照以下教程
答案 1 :(得分:1)
我检查了互联网并注意到最近1或2天内与此问题相关的一些讨论,他们似乎与Facebook有关。因此,如果您的代码将消息和图像成功发布到Twitter,那么请不要担心!你做得对。
https://stackoverflow.com/questions/14868518/sharekit-not-sharing-link-to-facebook/
答案 2 :(得分:0)
I have resolved through open present-view controller in navigation-bar.it may help you.
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:shareFrom];
[controller addImage:self.photoImageView.image];
[controller addURL:[NSURL URLWithString:dayCareWebsite]];
dispatch_async(dispatch_get_main_queue(), ^ {
[self.navigationController presentViewController:controller animated:YES completion:nil];
});