检测在 UIActivityViewController 中将选择哪个活动 [英] Detect which activity will be selected in UIActivityViewController
问题描述
我打算使用 UIActivityViewController 将文本分享到 Twitter 等.我需要将不同的文本分享到 Twitter、电子邮件等.因此,我需要根据用户选择动态更改文本.我可以知道一种方法吗?
I plan to use UIActivityViewController to share text to twitter, etc. I need to share different text to twitter, email, etc. As a result, I need to change text dynamically based on user selection. May I know a way to do?
我知道这样的方法.但只有在操作完成后才能更改文本.UIActivityViewController - 有没有办法知道哪个活动被选中了?
I know a way like this. But it is only after action is done and I can't change text. UIActivityViewController - is there a way to know which activity was selected?
推荐答案
您可以实现 UIActivityItemSource
及其 itemForActivityType:
方法来提供与用户选择相匹配的内容.
You can implement an UIActivityItemSource
and its itemForActivityType:
method to provide content to match the user's selection.
这在 NSHipster 上有解释.为方便起见,我复制/粘贴了相关的 Objective-C 代码和描述:
This is explained on NSHipster. For your convenience I copy/pasted the relevant Objective-C code and description:
如何使用此功能的一个示例是自定义消息,具体取决于它是要在 Facebook 还是 Twitter 上共享.
One example of how this could be used is to customize a message, depending on whether it's to be shared on Facebook or Twitter.
if ([activityType isEqualToString:UIActivityTypePostToFacebook]) {
return NSLocalizedString(@"Like this!",nil);
} else if ([activityType isEqualToString:UIActivityTypePostToTwitter]) {
return NSLocalizedString(@"Retweet this!",nil);
} else {
return nil;
}
这篇关于检测在 UIActivityViewController 中将选择哪个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!