如何用UIActivityItemProvider设置邮件主题 [英] How to set mail subject with UIActivityItemProvider

查看:724
本文介绍了如何用UIActivityItemProvider设置邮件主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 UIActivityViewController 通过电子邮件共享信息。我们可以发送电子邮件与身体,附件没有问题。但是我们如何设置电子邮件的标题。

I am using UIActivityViewController for sharing information through email. We are able to send email with body, attachments with no problem. But how do we set the subject title for the email.

我注意到这个问题:如何在UIActivityViewController中设置邮件主题?
接受的解决方案是使用 UIActivityItemSource 与此以下API
activityViewController:subjectForActivityType:。但是,我们的代码不符合 UIActivityItemSource ,因为我们使用 UIActivityItemProvider

I notice this question: How to set a mail Subject in UIActivityViewController? The accepted solution is using UIActivityItemSource with this following API activityViewController:subjectForActivityType:. However, our code doesn't conform to UIActivityItemSource because we are using UIActivityItemProvider.


UIActivityItemSource

您可以使用此协议在您要从应用程序的一个现有对象提供数据的情况下,而不是创建单独的UIActivityItemProvider对象。

You can use this protocol in situations where you want to provide the data from one of your app’s existing objects instead of creating a separate UIActivityItemProvider object.

所以完整的问题是:

如果我使用 UIActivityItemProvider 而不是UIActivityItemSource设置电子邮件主题?

How do I set the email subject if I am using UIActivityItemProvider instead of UIActivityItemSource?

推荐答案

定义您的自定义项目提供者:

Define your custom item provider:

@interface CustomProvider : UIActivityItemProvider
@end

添加到您的实现中:

@implementation CustomProvider

// Some other code ... -(id)item and etc. 

- (NSString *) activityViewController:(UIActivityViewController *)activityViewController
               subjectForActivityType:(NSString *)activityType
{
      return @"A dummy Title";
}

@end

请注意, UIActivityItemProvider 将自动符合 UIactivityItemSource 协议。不同的是,您不必为 UIactivityItemSource 协议实现 @required API。

Notice that UIActivityItemProvider will automatically conform to UIactivityItemSource protocol. The difference is, you don't have to implement those @required API for UIactivityItemSource protocol.

这篇关于如何用UIActivityItemProvider设置邮件主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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