I have a case follows:
- In app, i create a UIButton, when click will show a popup share facebook like UIActivityViewController. But i don't known get popup share facebook from UIActivityViewController. I need help everybody.
THANK YOU SO MUCH !!!
I have a case follows:
THANK YOU SO MUCH !!!
You need to create a UIActivityViewController and specify the items you wish to share:
- (IBAction)buttonPressed:(id)sender
{
NSString *textToShare = @"Put text here";
UIImage *imageToShare = _img;
NSArray *itemsToShare = @[textToShare, imageToShare];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
[self presentViewController:activityViewController animated:TRUE completion:nil];
}
If you wish to exclude any activity types you can do so by adding:
// add an array of activity types to exclude
activityViewController.excludedActivityTypes = @[UIActivityTypeMail, UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypePostToTwitter, UIActivityTypePostToWeibo];
before presenting the activityViewController.
Also, to see the "share on Facebook" option, you need to be logged in to Facebook on the device, as stated in this answer.
///
Option 2 - without UIActivityController
If you do not want to use the Activity Controller, but instead just directly open the iOS social sharing dialog, you can do that by importing the Social
framework and then using the Social Compose View Controller (SLComposeViewController
)
// import Social framework
#import <Social/Social.h>
// check if there is an account for Facebook
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *fbController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
// set up a completion handler (optional)
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
[fbController dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
break;
case SLComposeViewControllerResultDone:
break;
}};
[fbController addImage:imageToPost];
[fbController setInitialText:textToPost];
[fbController addURL:urlToPost];
[fbController setCompletionHandler:completionHandler];
[self presentViewController:fbController animated:YES completion:nil];
}