Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use UIActivityViewController to share on Facebook ?

I am trying to use UIActivityViewController to share on facebook. When I am using the

UIImage* image = [UIImage imageNamed:@"image1.png"];
NSArray* dataToShare = @[@"test",image];
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:dataToShare
                                  applicationActivities:nil];
activityViewController.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll];

I can't see the "Share on Facebook" icon although I didn't exclude "UIActivityTypePostToFacebook". isn't there a predefined UIActivity for facebook ?

Thanks

like image 510
Ulile Avatar asked Mar 03 '13 18:03

Ulile


2 Answers

you must be logged in your iphone settings: Settings -> facebook

like image 112
amau96 Avatar answered Nov 15 '22 14:11

amau96


Try this: if you want only facebook icon to share:

-(IBAction)shareButtonPressed:(id)sender { NSLog(@"shareButton pressed");

NSString *texttoshare = _txt;
UIImage *imagetoshare = _img;
NSArray *activityItems = @[texttoshare, imagetoshare];    
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypePostToTwitter, UIActivityTypePostToWeibo];
[self presentViewController:activityVC animated:TRUE completion:nil];
}

//in the list of excluded activity type insert any other kind of activitytypes you want to exclude

like image 33
Davide Avatar answered Nov 15 '22 15:11

Davide