如何使用可用的共享选项显示默认的iOS 6共享操作表? [英] How to display the default iOS 6 share action sheet with available share options?

查看:83
本文介绍了如何使用可用的共享选项显示默认的iOS 6共享操作表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Some apps show a default action sheet in iOS 6 with sharing options.

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

Social Framework only has two classes, one for composing and one for request.

我发现的是使用SLComposeViewController为特定服务编写组件在显示之前,如果服务可用,我必须手动查询。然后我还必须使用自己的图标创建自己的操作表。

What I found though is about composing for a particular service with SLComposeViewController and before showing this I must query by hand if the service is available. And then I also have to create my own action sheet with own icons.

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

How do those apps show this default share options action sheet in iOS 6? Or are they using an open source framework?

推荐答案

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

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:

- (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



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

这篇关于如何使用可用的共享选项显示默认的iOS 6共享操作表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆