[英]iOS: Disabling WhatsApp in UIActivityViewController?
I'm using the following code to share a string only to Facebook using UIActivityViewController 我正在使用以下代码使用UIActivityViewController仅将字符串共享给Facebook
UIActivityViewController *activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:activityItems
applicationActivities:nil];
activityViewController.excludedActivityTypes = @[UIActivityTypePostToWeibo,
UIActivityTypeMessage,
UIActivityTypeMail,
UIActivityTypePrint,
UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo,
UIActivityTypePostToTencentWeibo,
UIActivityTypeAirDrop,
UIActivityTypePostToTwitter];
[self presentViewController:activityViewController animated:YES completion:^{
...
}
This works except it also shows the WhatsApp icon and the more icon. 除了显示WhatsApp图标和更多图标之外,此方法有效。 Is there a way to remove these two?
有没有办法删除这两个? Thanks in advance!
提前致谢!
No, you can only remove activity types that Apple has provided constants for. 不可以,您只能删除Apple提供的常量的活动类型。 There is no way to remove 3rd party apps that appear or the "More..." activity.
无法删除出现的第三方应用程序或“更多...”活动。
If you only want to share with a single, specific app, there's no point in using a UIActivityController
. 如果您只想与一个特定的应用共享,那么使用
UIActivityController
是没有意义的。
Use one of the various Facebook libraries/APIs to share your data with Facebook. 使用各种Facebook库/ API之一与Facebook共享您的数据。
Whilst rmaddy's answer used to be true, for anyone coming across this since iOS 10 it's fairly simple to do: 尽管rmaddy的答案曾经是正确的,但对于iOS 10以后遇到此问题的任何人来说,这样做都非常简单:
activityController.excludedActivityTypes = [
UIActivity.ActivityType(rawValue: "net.whatsapp.WhatsApp.ShareExtension")
]
If you want to hide other non-system activity types, you can share to them, and then use the identifier returned in the completionWithItemsHandler
closure: 如果要隐藏其他非系统活动类型,可以与它们共享,然后使用在
completionWithItemsHandler
闭包中返回的标识符:
shareActivityController.completionWithItemsHandler = { [weak self] (activityType, completed, returnedItems, activityError) in
print("Activity Type", activityType?.rawValue ?? "?") // <--- Use the identifier this logs!
}
Although admittedly in the case of the OP's question, this still isn't going to help you as to limit it to only Facebook, you'd have to install all the other thousands of apps with share activities in order to disable them all! 尽管在OP的问题中确实可以接受,但这仍然不能帮助您将其限制为仅 Facebook,但您必须安装所有其他数千个具有共享活动的应用程序才能禁用它们!
Here are all the identifiers for apps I happened to have installed on my iPhone: 这是我刚安装在iPhone上的应用程序的所有标识符:
UIActivity.ActivityType(rawValue: "com.apple.reminders.RemindersEditorExtension"),
UIActivity.ActivityType(rawValue: "com.apple.mobilenotes.SharingExtension"),
UIActivity.ActivityType(rawValue: "net.whatsapp.WhatsApp.ShareExtension"),
UIActivity.ActivityType(rawValue: "pinterest.ShareExtension"),
UIActivity.ActivityType(rawValue: "com.facebook.Messenger.ShareExtension"),
UIActivity.ActivityType(rawValue: "com.tinyspeck.chatlyio.share"), // Slack!
UIActivity.ActivityType(rawValue: "ph.telegra.Telegraph.Share"),
UIActivity.ActivityType(rawValue: "com.google.Drive.ShareExtension"),
UIActivity.ActivityType(rawValue: "com.toyopagroup.picaboo.share"), // Snapchat!
UIActivity.ActivityType(rawValue: "wefwef.YammerShare"),
UIActivity.ActivityType(rawValue: "com.fogcreek.trello.trelloshare"),
UIActivity.ActivityType(rawValue: "com.linkedin.LinkedIn.ShareExtension"),
UIActivity.ActivityType(rawValue: "com.hammerandchisel.discord.Share"),
UIActivity.ActivityType(rawValue: "com.google.Gmail.ShareExtension"),
UIActivity.ActivityType(rawValue: "com.google.inbox.ShareExtension"),
UIActivity.ActivityType(rawValue: "com.riffsy.RiffsyKeyboard.RiffsyShareExtension"), //GIF Keyboard by Tenor
UIActivity.ActivityType(rawValue: "com.google.hangouts.ShareExtension"),
UIActivity.ActivityType(rawValue: "com.ifttt.ifttt.share")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.