实现共享功能的标准方法 [英] standard way to implement share as function

查看:48
本文介绍了实现共享功能的标准方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 iOS 中实现共享为..."功能.例如,按钮名称为共享为..."并弹出一个对话框,其中包括电子邮件、短信、Facebook、Twitter 等项目.我想知道是否有一个标准对话框来完成这项工作.

I need to implement a "share as..." function in iOS. For example a button names "share as..." and popup a dialog which includes items like Email, SMS, Facebook, Twitter. I wonder if there have a standard dialog do this job.

推荐答案

经过搜索,我发现在 iOS6 中使用 UIActivityViewController 的方法似乎很标准".

After searching, I found a way seems quite "standard" way in iOS6 by using UIActivityViewController.

以下是来自 developer.apple.com 的描述:

Following is the description from developer.apple.com:

UIActivityViewController 类是一个标准的视图控制器,您可以使用它从您的应用程序中提供各种服务.该系统提供多种标准服务,例如将项目复制到粘贴板、将内容发布到社交媒体网站、通过电子邮件或短信发送项目等.应用还可以定义自定义服务.

The UIActivityViewController class is a standard view controller that you can use to offer various services from your application. The system provides several standard services, such as copying items to the pasteboard, posting content to social media sites, sending items via email or SMS, and more. Apps can also define custom services.

以下是我使用 UIActivityViewController 设法生成的对话框

And following is a dialog I managed to produce by using UIActivityViewController

以下是我使用的源代码:

And following is the source code I use:

NSArray *activityItems = [NSArray arrayWithObjects: share_text.text, share_image.image , nil];

    UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
    [self presentViewController:activityController animated:YES completion:nil];

这篇关于实现共享功能的标准方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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