0

I want to share image using UIActivityViewController. This is my code.

- (IBAction)shareBUttonClick:(id)sender
{
   for(int i=0; i<[self.imagesDataArray count];i++)
  {
     [imageView sd_setImageWithURL:[NSURL URLWithString:[self.imagesDataArray objectAtIndex:i]] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];  
     NSArray *postItems=@[imageView];
    UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:postItems applicationActivities:nil];

 //if iPhone
 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
    [self presentViewController:controller animated:YES completion:nil];
    }
//if iPad
else 
    {
    // Change Rect to position Popover
    UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:controller];
    [popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }
 }
}

but, its giving me null(UIActivityViewController open in real device but sharing not there)

Please help me.

Mahendra
  • 8,448
  • 3
  • 33
  • 56
Ketan Odedra
  • 1,215
  • 10
  • 35

2 Answers2

2

you can use sdwebimage downloader async , then call upload function:

 [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:imageUrl] options:SDWebImageDownloaderUseNSURLCache progress:nil completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {

                        if (image && finished) {
    // now upload   
                              [self sendImageToShare:(UIImage *)image];
                        }
                    }]; 


    /*********************/


    - (void)sendImageToShare:(UIImage *)yourImage {
        if (yourImage) {
        NSMutableArray *activityItems= [NSMutableArray arrayWithObjects:yourImage, nil];
        UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];

        [self presentViewController:activityViewController animated:YES completion:nil];
    }

     }
Ajjjjjjjj
  • 669
  • 4
  • 12
1

first you need to prepare all URLs and prefetch images

    NSMutableArray * urls = [NSMutableArray   arrayWithCapacity:things.count];
    for(int i=0; i<[self.imagesDataArray count];i++) {
        [urls addObject:[NSURL URLWithString:   self.imagesDataArray[i]]];
    }
    [SDWebImagePrefetcher sharedImagePrefetcher]

with callback, then you can put downloaded images into share controller

Vadim Kozak
  • 420
  • 3
  • 11