在我的应用程序中有共享选项,所以我想在Actionsheet中打开该共享选项。 如何实现这一功能?
NSArray * itemsArray = @[@"www.google.com", @"Google", @"5.png"]; // Anything you want to share
NSArray * applicationActivities = nil;
UIActivityViewController * activityViewController = [[UIActivityViewController alloc] initWithActivityItems:itemsArray applicationActivities:applicationActivities];
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0"))
{
activityViewController.popoverPresentationController.sourceView = self.view;
}
[self presentViewController:activityViewController animated:YES completion:nil];
我想分配自己的自定义图片,链接和文字,以便如何实现这个
答案 0 :(得分:1)
为什么不使用UIActivityViewController
?因此系统可以处理分享位置:
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
UIImage * image = [UIImage imageNamed:@"yourimage.png"];
NSArray * itemsArray = @[image]; // Anything you want to share
NSArray * applicationActivities = nil;
UIActivityViewController * activityViewController = [[UIActivityViewController alloc] initWithActivityItems:itemsArray applicationActivities:applicationActivities];
activityViewController.excludedActivityTypes = @[
UIActivityTypePostToWeibo,
UIActivityTypeAssignToContact,
UIActivityTypeAirDrop,
UIActivityTypeAddToReadingList
// Whatever you want to exclude
];
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")){
activityViewController.popoverPresentationController.sourceView = self.view;
}
[self presentViewController:activityViewController animated:YES completion:nil];