1

I was looking for UIActivityViewController to share different string or image with different type of activity type i.e. for Print option, sharing option (facebook, twitter).

But didn't get any option to do that. Please advice.

Thanks!

Minkle Garg
  • 723
  • 3
  • 9
  • 35

2 Answers2

0

Try this Code

-(void)shareContent{

NSString * message = @"My too cool Son";

UIImage * image = [UIImage imageNamed:@"boyOnBeach"];

NSArray * shareItems = @[message, image];

UIActivityViewController * avc = [[UIActivityViewController alloc] initWithActivityItems:shareItems applicationActivities:nil];

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

}
Jigar
  • 1,801
  • 1
  • 14
  • 29
  • Above code is to share the same content for any activity type, but suppose If I want to share different image for print option then what to do – Minkle Garg Apr 04 '17 at 14:08
  • @MinkleGarg if you want to share multiple image than create image of array.or if you want to share dynamic image than set your ImageView control name. – Jigar Apr 05 '17 at 06:00
  • suppose activityviewcontroller appears, now user want to share the image for the print activity, but this image should be different than other activities shared image. So can we paas different image in case user click on print option and if user choose (facebook, twitter etc.) then image should be different. Is there any method to paas different content on the selection of activity type. – Minkle Garg Apr 05 '17 at 08:01
  • @MinkleGarg check this http://stackoverflow.com/questions/26551408/share-data-with-different-types-in-uiactivityviewcontroller?noredirect=1&lq=1 – Jigar Apr 05 '17 at 08:07
  • 1
    @MinkleGarg also try this demo http://www.albertopasca.it/whiletrue/2012/10/objective-c-custom-uiactivityviewcontroller-icons-text/ – Jigar Apr 05 '17 at 08:12
  • I tried to make dummy sample, but it is showing error: Undefined symbols for architecture armv7: "_OBJC_CLASS_$_APActivityIcon", referenced from: – Minkle Garg Apr 06 '17 at 10:20
  • @MinkleGarg check this http://stackoverflow.com/questions/6429494/undefined-symbols-for-architecture-armv7 .add your update code. – Jigar Apr 06 '17 at 10:22
  • I tried with every possible solution, but again the issue is same ;( – Minkle Garg Apr 06 '17 at 13:29
  • Should I email you? – Minkle Garg Apr 06 '17 at 13:47
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/140084/discussion-between-ios-dev-and-minkle-garg). – Jigar Apr 06 '17 at 13:47
  • @MinkleGarg upload demo in drive and send link – Jigar Apr 06 '17 at 13:48
  • I have shared the link on chat room – Minkle Garg Apr 11 '17 at 04:28
  • @Jigar, correct url: https://www.albertopasca.it/whiletrue/objective-c-custom-uiactivityviewcontroller-icons-and-text/ – elp Sep 18 '18 at 16:08
0

You can do this using UIActivityItemProvider

in .h File

@interface APActivityProvider : UIActivityItemProvider <UIActivityItemSource>

@end

in .m file

@implementation APActivityProvider

- (id) activityViewController:(UIActivityViewController *)activityViewController
          itemForActivityType:(NSString *)activityType {
     if ( [activityType isEqualToString:UIActivityTypePostToFacebook] )
        return @"This is a facebook post!";
    if ( [activityType isEqualToString:UIActivityTypeMessage] )
        return @"SMS message text";
    if ( [activityType isEqualToString:UIActivityTypeMail] )
        return @"Email text here!";

}

- (void) shareAppData  {
     APActivityProvider *ActivityProvider = [[APActivityProvider alloc] initWithPlaceholderItem: @“”];
     NSArray *Items = @[ActivityProvider];


     UIActivityViewController *ActivityView = [[UIActivityViewController alloc]
                                               initWithActivityItems:Items
                                               applicationActivities:nil];

     [ActivityView setValue:@“Title for email” forKey:@"subject"];

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

     [ActivityView setCompletionHandler:^(NSString *act, BOOL done)
     {
         NSString *ServiceMsg = nil;
         if ( [act isEqualToString:UIActivityTypeMail] ) 
           ServiceMsg = @"Mail sended!";
         if ( [act isEqualToString:UIActivityTypePostToTwitter] )  
        ServiceMsg = @"Post on twitter, ok!";
         if ( [act isEqualToString:UIActivityTypePostToFacebook] ) 
        ServiceMsg = @"Post on facebook, ok!";
         if ( [act isEqualToString:UIActivityTypeMessage] )        
        ServiceMsg = @"SMS sended!";

         if (done)
         {
             UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:ServiceMsg message:@"" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
             [Alert show];
         }
     }];
}
Patrick R
  • 6,621
  • 1
  • 24
  • 27