Почему я не могу подключить методы WKCustomProtocol - PullRequest
0 голосов
/ 17 декабря 2018

WKCustomProtocol - это форма класса WebKit исходный код , Я уже отладил его.Он существует

HDWebURLProtocol super Суперкласс WKCustomProtocol - это NSURLProtocol.Я подключаю свой собственный класс 'HDWebURLProtocol', который был успешным, но WKCustomProtocol не был успешным;

Я использую Xcode 10.1, симулятор iOS 12.1 , Отладочный прогон Код WebKit

Это мой код:

+ (void)exchange {

    Class WKCustomProtocolClass = object_getClass(NSClassFromString(@"WKCustomProtocol")); // HDWebURLProtocol

    SEL canInitWithRequest = NSSelectorFromString(@"canInitWithRequest:");
    SEL af_canInitWithRequest = NSSelectorFromString(@"fix_canInitWithRequest:");

    BOOL add1 = class_addMethod(WKCustomProtocolClass,
                                canInitWithRequest,
                                class_getMethodImplementation(WKCustomProtocolClass, canInitWithRequest),
                                "B@:@");

    BOOL add2 = class_addMethod(WKCustomProtocolClass,
                                af_canInitWithRequest,
                                (IMP)af_canInitWithRequest2,
                                "B@:@");

    NSLog(@"%d,%d", add1, add2);

    Method orgi = class_getClassMethod(WKCustomProtocolClass, canInitWithRequest);
    Method after = class_getClassMethod(WKCustomProtocolClass, af_canInitWithRequest);

    method_exchangeImplementations(orgi, after);
}

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"

BOOL af_canInitWithRequest2(id sender, SEL cmd, NSURLRequest *req) {
    SEL canInitWithRequest = NSSelectorFromString(@"fix_canInitWithRequest:");
    return [sender performSelector:canInitWithRequest withObject:req];
}

#pragma clang diagnostic pop

скриншоты точки останова

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...