如何在整个应用程序中禁用iOS

如何在整个应用程序中禁用iOS

本文介绍了如何在整个应用程序中禁用iOS 11拖动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于安全考虑,我想禁用新的iOS 11拖放功能。在我的整个应用中删除功能。更具体地说,拖动部分。

For security reasons I want to disable the new iOS 11 drag & drop feature within my whole app. More specifically the drag part.

在iOS 11中,默认情况下,所有可以选择文本的地方的文本都会发生 - 弹出窗口,文本视图,网页浏览等。

In iOS 11 it's happening by default for text in all places where text can be selected - popups, textviews, webviews, etc.

推荐答案

找到解决方案。方法是调用UIDragInteraction的isEnabled方法,在你的app可能需要的情况下返回NO。请注意,通常方法调整不是一个好主意。

Found a solution. It is to method swizzle the isEnabled method of UIDragInteraction to return NO in the situations your app may need. Note that normally it's not a good idea to method swizzle.

@implementation UIDragInteraction (TextLimitations)
+ (void)load
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{

        Class class = [self class];

        SEL originalSelector = @selector(isEnabled);
        SEL swizzledSelector = @selector(restrictIsEnabled);

        Method originalMethod = class_getInstanceMethod(class, originalSelector);
        Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);

        BOOL didAddMethod =
        class_addMethod(class,
                        originalSelector,
                        method_getImplementation(swizzledMethod),
                        method_getTypeEncoding(swizzledMethod));

        if (didAddMethod) {
            class_replaceMethod(class,
                                swizzledSelector,
                                method_getImplementation(originalMethod),
                                method_getTypeEncoding(originalMethod));
        } else {
            method_exchangeImplementations(originalMethod, swizzledMethod);
        }
    });
}

-(BOOL)restrictIsEnabled
{
    if (restrictedCondition)
    {
        return NO;
    }
    return [self restrictIsEnabled];
}

这篇关于如何在整个应用程序中禁用iOS 11拖动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 06:39