When you a share a url with the UIActivityViewController, it just shows the Safari compass. I get that this is supposed to show the user that they are sharing a link, but is it possible to get this to show a thumbnail/image instead? I realize it does this if I try and share an image, but I wanted to just share a link here.
Asked
Active
Viewed 1,843 times
1 Answers
1
Instead of sharing an NSURL
directly, you can share an object that implements the UIActivityItemSource
protocol. This can just be an object that wraps the NSURL
and returns it when the activityViewController:itemForActivityType:
method is called.
You can then implement the optional method activityViewController:thumbnailImageForActivityType:suggestedSize:
to provide a thumbnail for the share dialog.
For example:
@interface URLWrapper:UIActivityItemProvider
@property (nonatomic, strong) NSURL *url;
@end
@implementation URLWrapper
+ (instancetype)activityItemSourceUrlWithUrl:(NSURL *)url {
URLWrapper *wrapper = [[self alloc] initWithPlaceholderItem:@""];
wrapper.url = url;
return wrapper;
}
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
return [self activityViewController:activityViewController itemForActivityType:nil];
}
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {
return self.url;
}
- (UIImage *)activityViewController:(UIActivityViewController *)activityViewController thumbnailImageForActivityType:(NSString *)activityType suggestedSize:(CGSize)size {
UIImage* thumbnail; // get image from somewhere!
return thumbnail;
}
@end
You can then share wrapped URLs just as you would share normal instances of NSURL
.

neowinston
- 7,584
- 10
- 52
- 83

AHM
- 5,145
- 34
- 37
-
2This does not seem to work (tested with XCode7/iOS9). thumbnailImageForActivityType is never called. Tried with Facebook and mail share options. Perhaps it works with some other share option. – Ciryon Sep 30 '15 at 08:16
-
1I think thumbnailImageForActivityType is used for sharing images like in Photos you can select images – CiNN Apr 22 '16 at 09:26