Search code examples
imageios6uiimageafnetworkinguiactivityviewcontroller

Using a URL to share an image with iOS 6 and UIActivityViewController


I am using iOS 6's UIActivityViewController. I would like to share an image that is not available locally on my iPhone, but that it is available on a remote URL.

NSString *textToShare = _eventoTitle;
UIImage *imageToShare = [UIImage imageNamed:_iconUrl];
NSURL *url = [NSURL URLWithString:_permalink];
NSArray *activityItems = [[NSArray alloc]  initWithObjects:textToShare, imageToShare, url, nil];

Unfortunately, this is not working. What am I doing wrong?

I have also tried to use the AFNetworking library:

UIImage *imageToShare = [UIImage alloc];
[*imageToShare setImageWithURL:[NSURL URLWithString:_iconUrl]];

This is not working too.

_iconUrl is something like http://www.mysite.com/picture.png

Thank you, Francesco


Solution

  • Try with:

    UIImage *imageToShare = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", _iconUrl]]]];
    

    Matteo