Sharing Content With UIActivityViewController

Sharing Content With UIActivityViewController

In this post we will give you information about Sharing Content With UIActivityViewController. Hear we will give you detail about Sharing Content With UIActivityViewControllerAnd how to use it also give you demo for it if it is necessary.


Before the release of iOS 6.0, the sharing of content was quite tiresome. There were numerous third party libraries that provided the content sharing feature but they weren’t that effective and efficient.

Fortunately, Apple then added a class UIActivityViewController that made the sharing of content to any service very simple. You just have to tell the class what kind of content you have and the class will do that work for you.


The most interesting thing about UIActivityViewController is that it automatically detects the apps that user has installed in his device. If they have Twitter, then they can post tweets with the content; if they have Facebook, then they can post content to their Facebook timeline; if they have configured a printer with their device, then they can print documents, images and more. You just have to tell the type of content you have and the class will do the rest of the work.




Below is an example to share an image:

if let image = UIImage(named:"myImage"){

    let activityViewController:UIActivityViewController = UIActivityViewController(activityItems:[image],applicationActivities: nil)

    self.present(activityViewController,animated:true,completion: nil)

}



You can also remove the apps that you don’t want to be shown in the controller and don’t want to share the content with.


Here is an example to share text as well as image with the excluded apps:


let shareText ="Hello, world!"

if let image = UIImage(named:"myImage"){

    let activityViewController:UIActivityViewController = UIActivityViewController(activityItems:[shareText, image],applicationActivities: nil)

    let excludedTypes:[UIActivityType]=[.postToVimeo,.postToTwitter,.assignToContact,.saveToCameraRoll,.markupAsPDF]

    activityViewController.excludedActivityTypes= excludedTypes

     self.present(activityViewController,animated:true,completion: nil)

}

Try this..

Hope this code and post will helped you for implement Sharing Content With UIActivityViewController. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  27  =  37

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US