The UIActivityViewController class is a standard view controller that you can use to offer various services from your application. The system provides several standard services, such as copying items to the pasteboard, posting content to social media sites, sending items via email or SMS, and more. Apple Documentation.

Below is the simple code to implement it. By default it will take all the available option in your phone to share, but we can exclude activities using excludeactivityType method

   NSString *messageToShare = @”Look at this awesome website  for iOS app Development!”;
        NSURL *myWebsiteLink = [NSURL URLWithString:@”https://iostpoint.wordpress.com/”%5D;

        NSArray *objectsToShare = @[messageToShare, myWebsiteLink];

        UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];

        NSArray *excludeActivities = @[UIActivityTypeAirDrop,
                                       UIActivityTypePrint,
                                       UIActivityTypeOpenInIBooks,
                                       UIActivityTypeAssignToContact,
                                       UIActivityTypeSaveToCameraRoll,
                                       UIActivityTypeAddToReadingList,
                                       UIActivityTypePostToFlickr,
                                       UIActivityTypePostToVimeo];

        activityVC.excludedActivityTypes = excludeActivities;

        [self presentViewController:activityVC animated:YES completion:nil];

Use this code inside the button action or anywhere according to Your need. Enjoy coding 🙂

Advertisements