UIActivityViewController - NSURL ActivityItemProvider by default thumbnail

I am trying to figure out what sets the default thumbnail in the folder (instead of the embossed Safari icon) when you use NSURL to attach the link to the UIActivityViewController. I feel like I've seen websites like google and itunes store so these thumbnails are useful images. I feel that the embossed safari icon is too vague and the user does not know which link he is sending.

Perhaps this is something in the html headers for this link?

Thanks!

vague safari icon

+4
source share
2 answers

I had to decrypt all the UIActivityViewController documentation recently. You probably don't want to include UIImage with your NSURL in the blind hope that it will be used as a thumbnail. As far as I understand, you cannot be sure what UIActivity will do with the image, it can post this instead of the URL.

In your activityItems array parameter initWithActivityItems:applicationActivities: instead of NSURL pass the object you create that conforms to the UIActivityItemSource protocol. You can have any controller that opens a UIActivityViewController object that conforms to this protocol, for example, in this case your activityItems parameter will be @[self] .

In addition to implementing the 2 required methods, activityViewControllerPlaceholderItem: and activityViewController:itemForActivityType: in order to both simply return your NSURL and implement this to return any thumbnail that you like:

 - (UIImage *)activityViewController:(UIActivityViewController *)activityViewController thumbnailImageForActivityType:(NSString *)activityType suggestedSize:(CGSize)size; 

Pay attention to one thing that is not actually specified in the documentation, if you really need to have several objects in your activityItems array and update it to use UIActivityItemSource (or UIActivityItemProvider ) objects, then it needs a separate object to return each of source data objects in the source array. For example, if your data elements are NSURL and a UIImage , then make one UIActivityItemSource to return the NSURL and the other to return the UIImage . Having one UIActivityItemSource that returns an NSURL and UIImage , as your original activityItems array does not work.

+3
source

Have you tried to set the activityImage property for the UIActivity derived object for the image you want to display in the folder?

"For UIActivityTypePostToTwitter: The object places the provided content in the feed of Twitter users. When using this service, you can provide NSString, NSAttributedString, UIImage, AVAsset, and NSURL objects as data for activity elements. You can also specify NSURL objects whose contents use the asset scheme - libraries.

Notice the UIImage object that you can include in the array that is passed to the UIActivityViewController. This link describes more about the activityImage property, http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIActivity_Class/Reference/Reference.html#//apple_ref/occ/instm/UIActivity/activityType .

Kevin

0
source

Source: https://habr.com/ru/post/1447039/


All Articles