如何从 UIActivityViewController 中排除 Notes 和 Reminders 应用程序? [英] How to exclude Notes and Reminders apps from the UIActivityViewController?

查看:25
本文介绍了如何从 UIActivityViewController 中排除 Notes 和 Reminders 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 UIActivityViewController 并将 StringURL 传递给它.显然,这会将 UIActivityViewController 配置为使用一些我想排除的项目(我的目标是分享有关我的应用程序的信息).

I am creating a UIActivityViewController and pass String and URL to it. This, obviously, configures the UIActivityViewController to use some items which I want to exclude (my objective is to share the info about my app).

通过设置适当的excludedActivityTypes,我设法排除了许多系统提供的活动(如添加到阅读列表").

I have managed to exclude lots of system provided activities (like 'Add to Reading list') by setting the appropriate excludedActivityTypes.

但是,我无法排除提醒和备注应用.有人可以建议一种方法吗?这些应用出现在列表中的第 3 和第 4 位,因此除非用户滚动,否则 Twitter 和 Facebook 不可见.

However, I am unable to exclude Reminders and Notes apps. Can someone suggest a way of doing it? These apps appear 3rd and 4th on the list and therefore make Twitter and Facebook not visible unless user scrolls.

推荐答案

有办法,但是涉及私有API.

有时 Apple 会例外,尤其是在您修复错误的情况下.

Sometimes Apple makes exceptions, especially if you fix a bug.

让我们深入了解细节...

Let's dive into details...

UIActivityViewController 有一个名为_availableActivitiesForItems:"的私有方法,它返回一个 UISocialActivity 对象数组.

UIActivityViewController has got a private method called "_availableActivitiesForItems:", which returns an array of UISocialActivity objects.

UISocialActivity 有一个有趣的属性,称为activityType",它返回一个域格式的活动类型.

UISocialActivity has got an interesting property, called "activityType", which returns a domain-formatted activity type.

经过一些测试,我设法发现了 Reminder 和 Notes 活动类型:

After some tests, I managed to discover the Reminder and Notes activity types:

  • com.apple.reminders.RemindersEditorExtension
  • com.apple.mobilenotes.SharingExtension

不幸的是,将这两种类型传递给.excludedActivityTypes"没有任何区别.

Unfortunately, passing those two types into ".excludedActivityTypes" didn't make any difference.

_availableActivitiesForItems:"来救援!

"_availableActivitiesForItems:" to the rescue!

老方法:

更新:我找到了更好的方法.

Update: I've found a better way to do it.

我发布的第一个解决方案在某些情况下不起作用,因此不应该被认为是稳定的.

The first solution I've posted doesn't work in some cases, thus shouldn't be considered stable.

标题:

#import <UIKit/UIKit.h>

@interface UISocialActivity : NSObject

- (id)activityType;

@end

@interface UIActivityViewController (Private)

- (id)_availableActivitiesForItems:(id)arg1;

@end

@interface ActivityViewController : UIActivityViewController

@end

实施:

@implementation ActivityViewController

- (id)_availableActivitiesForItems:(id)arg1
{
    id activities = [super _availableActivitiesForItems:arg1];
    NSMutableArray *filteredActivities = [NSMutableArray array];

    [activities enumerateObjectsUsingBlock:^(UISocialActivity*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {

        if (![[obj activityType] isEqualToString:@"com.apple.reminders.RemindersEditorExtension"] &&
            ![[obj activityType] isEqualToString:@"com.apple.mobilenotes.SharingExtension"]) {
            [filteredActivities addObject:obj];
        }

    }];

    return [NSArray arrayWithArray:filteredActivities];
    }
    @end

新方法:

标题:

@interface UIActivityViewController (Private)

- (BOOL)_shouldExcludeActivityType:(UIActivity*)activity;

@end

@interface ActivityViewController : UIActivityViewController

@end

实施:

@implementation ActivityViewController

- (BOOL)_shouldExcludeActivityType:(UIActivity *)activity
{
    if ([[activity activityType] isEqualToString:@"com.apple.reminders.RemindersEditorExtension"] ||
        [[activity activityType] isEqualToString:@"com.apple.mobilenotes.SharingExtension"]) {
        return YES;
    }
    return [super _shouldExcludeActivityType:activity];
}

@end

非法",但它有效.

很高兴知道它是否真的通过了 Apple 验证.

It would be great to know if it actually passes Apple validation.

这篇关于如何从 UIActivityViewController 中排除 Notes 和 Reminders 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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