-1

In my application having sharing option so i want to open that sharing option in Actionsheet. how how to achieve this functionality?

NSArray * itemsArray = @[@"www.google.com", @"Google", @"5.png"]; // Anything you want to share
NSArray * applicationActivities = nil;

UIActivityViewController * activityViewController = [[UIActivityViewController alloc] initWithActivityItems:itemsArray applicationActivities:applicationActivities];

if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0"))
{
     activityViewController.popoverPresentationController.sourceView = self.view;
}
[self presentViewController:activityViewController animated:YES completion:nil];

i want to assign my own custom image, link and text so how to achieve this

enter image description here

Monika Patel
  • 2,287
  • 3
  • 20
  • 45

1 Answers1

1

Why don't you use an UIActivityViewController instead? So the system can handle where to share it:

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)


UIImage * image = [UIImage imageNamed:@"yourimage.png"];
NSArray * itemsArray = @[image]; // Anything you want to share


    NSArray * applicationActivities = nil;

    UIActivityViewController * activityViewController = [[UIActivityViewController alloc] initWithActivityItems:itemsArray applicationActivities:applicationActivities];

    activityViewController.excludedActivityTypes = @[
                                                     UIActivityTypePostToWeibo,
                                                     UIActivityTypeAssignToContact,
                                                     UIActivityTypeAirDrop,
                                                     UIActivityTypeAddToReadingList
                                                     // Whatever you want to exclude
                                                     ];

    if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")){
        activityViewController.popoverPresentationController.sourceView = self.view;
    }

    [self presentViewController:activityViewController animated:YES completion:nil];
Pablo A.
  • 2,042
  • 1
  • 17
  • 27
  • NSArray * itemsArray = @[url ? url : [NSNull null], title ? title : [NSNull null], image ? image : [NSNull null]]; if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")){ activityViewController.popoverPresentationController.sourceView = viewController.view; } [viewController presentViewController:activityViewController animated:YES completion:nil]; got an error in this lines – Monika Patel Sep 04 '15 at 13:38
  • Replace `url`, `title` and `image` for your objects. Actually, just add to the array what you want to share. – Pablo A. Sep 04 '15 at 13:39
  • What error do you get? I modified my solution, just copy and paste the whole code and replace url, title and image by your objects – Pablo A. Sep 04 '15 at 13:41
  • use of undeclared identifier viewcontroller – Monika Patel Sep 04 '15 at 13:43
  • `viewController` is your view controller, so probably `self` for you, replace `viewController` by `self`. And url, title and image *must be your objects*. If you're sharing an image replace them with your image. – Pablo A. Sep 04 '15 at 13:44
  • but how to assign custom image to UIActivityViewController – Monika Patel Sep 05 '15 at 03:31
  • I edited the answer, with the steps I told you to do... I can't help more than that... If you need more help then show your code and we'll try to figure out what's wrong... – Pablo A. Sep 05 '15 at 08:12
  • i want only this 4 option 1.Mail 2.Contact 3.Whats App 4.Facebook . – Monika Patel Sep 05 '15 at 08:17
  • Exclude everything else then, in the 'excludeActivityTypes' array – Pablo A. Sep 05 '15 at 08:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/88864/discussion-between-stela-and-pablo-a). – Monika Patel Sep 05 '15 at 08:23