質問

I'm working on an app wich lists some music tracks from iTunes and I'm using SLComposeViewController to share the track Twitter with the album artwork in the tweet. It's working right now but when I click the share button it takes too much time to show me the "tweet interface" and the UI seems frozen.

I think it's because of the image loading but I don't know how to load it asynchronously. Because if I understand well, once I shown the SLComposeViewController I can't update it anymore...

This is the code I'm using :

NSString *textToShare = [[self.punchlinesArray objectAtIndex:[indexPath row]] objectForKey:@"quoteContent"];
NSString *imgUrlToShare = [[self.punchlinesArray objectAtIndex:[indexPath row]] objectForKey:@"artworkURL"];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imgUrlToShare]]];
SLComposeViewController *tweetSheet = [SLComposeViewController
                                       composeViewControllerForServiceType:SLServiceTypeFacebook];

[tweetSheet setInitialText:textToShare];
[tweetSheet addImage:image];

Cheers,

Bastien

役に立ちましたか?

解決

From the class reference of the SLComposeViewController addImage method:

This method returns NO if image does not fit in the currently available space or if the view controller has already been presented to the user (and therefore cannot be changed).

So you can still load the image asynchronously and on the completion block of your operation, set the image and present the view controller.

But you might need to see if the frozen UI is because of the image still loading or because the image size is just too big.

You can try first to load the image asynchronously and see if it helps: Download an asynchronous multiple images in UITableViewView?

While the image is being loaded, you can also put activity indicator and remove it on completion.

Otherwise, it might be the size of the image causing the issue and you will need to consider scaling down the image to be shared through Twitter.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top