如何显示默认的 iOS6共享行动表与可用的共享选项?

一些应用程序在 iOS6中显示了带有共享选项的默认行动表。

Social Framework 只有两个类,一个用于编写,一个用于请求。

但是我发现,在使用 SLComposViewController 为特定的服务进行组合之前,如果服务可用,我必须手动查询。然后我还必须创建自己的行动表与自己的图标。

在 iOS6中,这些应用程序如何显示默认的股票期权操作表?还是使用开源框架?

58841 次浏览

The UIActivityViewController stated in the other answer makes this trivial. All you have to do is specify the text/image/URL that you want to share and present the activity view controller modally and iOS will automatically display all applicable sharing services. Examples:

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];
}

Swift

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.compactMap({$0}), applicationActivities: nil)
if UIDevice.current.userInterfaceIdiom == .pad {
activityViewController.popoverPresentationController?.sourceView = view
}
present(activityViewController, animated: true, completion: nil)
}

Add this to use the 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];
}