How to create UIActivityViewController swift


 

UIActivityViewController in Swift tutorial

UIActivityViewController using swift is similar to as we create in objective C , you can read it how to create UIActivityViewController in objective C from  here. This post will give you an example of sharing image through UIActivityViewController in Swift.

Sharing image using UIActivityViewController in swift


Create a new project and select swift as development language. Add an image to your project and replace index.jpg with your image name. Open ViewController.swift and add below code to it.

 

 @IBAction func clickAction (sender:UIButton)

     {
         var image = UIImage(named:“index.jpg”)!;
         var objectToShare = [image]
        
         let activityViewController = UIActivityViewController(activityItems:objectToShare,  applicationActivities: nil)
        activityViewController.excludedActivityTypes  =  [UIActivityTypePostToWeibo,UIActivityTypePostToVimeo]
        self.presentViewController(activityViewController, animated: true, completion:nil)      
    }
 


Open storyBoard and drag UIButton to it. Connect the IBAction to it and compile and run it.

Where to go from here

in this post we learned about how to create UIActivityViewController in swift. UIActivityviewcontroller is basically used for sharing images or documents using different apps of user iPhone. If you are  having any problems then feel free to ask.

 
 
%d bloggers like this: