如何显示带有可用共享选项的默认iOS 6共享操作表?

有些应用程序会在iOS 6中显示默认操作表,并带有共享选项。

社交框架只有两个类,一个用于编写,一个用于请求。

我发现虽然是与SLComposeViewController组成一个特定的服务,并显示此之前,我必须手动查询服务是否可用。 然后,我也必须创build自己的图标自己的行动表。

这些应用程序如何在iOS 6中显示此默认的共享选项操作表? 还是他们使用开源框架?

UIActivityViewController在另一个答案中说明了这个微不足道的。 您只需指定要共享的文本/图像/ URL并以模态方式显示活动视图控制器,iOS将自动显示所有适用的共享服务。 例子:

Objective-C的

- (void)shareText:(NSString *)text andImage:(UIImage *)image andUrl:(URL *)url { NSMutableArray *sharingItems = [NSMutableArray new]; if (text) { [sharingItems addObject:text]; } if (image) { [sharingItems addObject:image]; } if (url) { [sharingItems addObject:url]; } UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil]; [self presentViewController:activityController animated:YES completion:nil]; } 

迅速

 func share(sharingText: String?, sharingImage: UIImage?, sharingURL: URL?) { let sharingItems:[AnyObject?] = [ sharingText as AnyObject, sharingImage as AnyObject, sharingURL as AnyObject ] let activityViewController = UIActivityViewController(activityItems: sharingItems.flatMap({$0}), applicationActivities: nil) if UIDevice.current.userInterfaceIdiom == .pad { activityViewController.popoverPresentationController?.sourceView = view } present(activityViewController, animated: true, completion: nil) } 

添加这个使用UIActivityViewController

 -(IBAction)shareButtonPressed:(id)sender { NSLog(@"shareButton pressed"); NSString *texttoshare = _txt; //this is your text string to share UIImage *imagetoshare = _img; //this is your image to share NSArray *activityItems = @[texttoshare, imagetoshare]; UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil]; activityVC.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypePrint]; [self presentViewController:activityVC animated:TRUE completion:nil]; }