• May
  • 16
  • 2015

Want to add image sharing to social media button? Or having trouble in your code for picture sharing button in iOS application?

Don’t worry!

Here is the steps and code to add picture share button:

Share an image to available social media with UIActivityViewController in iOS

Steps:

1. Add a button in view controller from your storyboard

2. Create a button method for your share button as follows:

-(IBAction)btnShareClick:(id)sender
{
UIButton *shareButton = (UIButton*)sender;
//image from project.
NSString *text = @"How to add sharing Button to your iOS app";
NSURL *url = [NSURL URLWithString:@"https://www.gurutechnolabs.com/code-for-sharing-picture-on-social-media-in-ios/"];
UIImage *imageShare = [UIImage imageNamed:@"star.png"];
NSArray *Items = [NSArray arrayWithObjects: imgShare, url, text, nil];
UIActivityViewController *ActivityView =[[UIActivityViewController alloc]initWithActivityItems:Items applicationActivities:nil];

// Exclude following activities.
NSArray *excludedActivities = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll,UIActivityTypeAirDrop];
ActivityView.excludedActivityTypes = excludedActivities;
ActivityView.popoverPresentationController.sourceView= shareButton;

[self presentViewController:ActivityView animated:YES completion:nil];
}
Activity types are divided up into “action” and “share” types:

UIActivityCategoryAction

  • UIActivityTypePrint
  • UIActivityTypeCopyToPasteboard
  • UIActivityTypeAssignToContact
  • UIActivityTypeSaveToCameraRoll
  • UIActivityTypeAddToReadingList
  • UIActivityTypeAirDrop

UIActivityCategoryShare

  • UIActivityTypeMessage
  • UIActivityTypeMail
  • UIActivityTypePostToFacebook
  • UIActivityTypePostToTwitter
  • UIActivityTypePostToFlickr
  • UIActivityTypePostToVimeo
  • UIActivityTypePostToTencentWeibo
  • UIActivityTypePostToWeibo

3. Map above method to Touchup inside event of that button

You are done. Enjoy Sharing !!

If this blog could not answer your question then you can hire iphone app developers who will assist you to integrate social sharing in your application.

Ravi Makhija

Ravi Makhija

A writer, an Entrepreneur. Curious about the internet of everything. Interested in the cutting edge landscape of mobile apps and SAAS products. Blogs for Guru Technolabs - A Mobile App Development Company.

Popular Blogs

Among the many digital tools that are being used with increasing frequency, the one that has the greatest...

Having a Best Website like opening a door and inviting…

In this internet era, the business website is the most…

The Live chat is the common thing now days, if…

Let's Discuss a Project

Please share your unique idea or project requirement with us, our business concern person will get back to you with further details.