次のメソッドを使用して、画像と URL をユーザーの Facebook ウォールに共有しています。問題は、投稿に画像を追加しているため、Facebook フォト アルバムに保存されてしまうことです。おそらくこれがデフォルトの動作ですが、ある時点でフォト アルバムではなく写真付きの壁に投稿していたことを誓います。
助けてくれてありがとう
- (IBAction)shareAction:(id)sender {
SLComposeViewController * fbController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbController setInitialText:@"App Name"];
NSIndexPath* indexPath = [tableView indexPathForCell:sideSwipeCell];
// NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
// output id of selected deal
#ifdef DEBUG
NSLog(@"deal id for selected row is %@", [[displayItems objectAtIndex:indexPath.row] objectForKey:@"id"]);
#endif
// display the youdeal deal image
link = [[displayItems objectAtIndex:indexPath.row] objectForKey:@"link"];
// download the youdeal deal image for FB posting
NSURL *url = [NSURL URLWithString:[[displayItems objectAtIndex:indexPath.row] objectForKey:@"image"]];
NSLog(@"url to image share %@", url);
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
NSLog(@"data to image share %@", data);
UIImage *tmpImage = [[UIImage alloc] initWithData:data];
NSLog(@"tmpImage to image share %@", tmpImage);
ydImage = tmpImage;
NSLog(@"ydimageview.image %@", ydImage);
// [NSThread detachNewThreadSelector:@selector(downloadAndLoadImage) toTarget:self withObject:nil];
[fbController setInitialText:@"Check out this link."];
[fbController addURL:[NSURL URLWithString:link]];
[fbController addImage:ydImage];
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
[fbController dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
#ifdef DEBUG
NSLog(@"User Cancelled.");
#endif
[self removeSideSwipeView:YES];
}
break;
case SLComposeViewControllerResultDone:
{
#ifdef DEBUG
NSLog(@"Posted");
#endif
[self removeSideSwipeView:YES];
CustomAlertView *fbAlert = [[CustomAlertView alloc] initWithTitle:@"App Name" message:@"Facebook Post Successful!" delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
[fbAlert show];
}
break;
}};
[fbController setCompletionHandler:completionHandler];
[self presentViewController:fbController animated:YES completion:nil];
}