Broadcom and Toutiao advertising SDK, callback method name the same conflict resolution

Problem description: Two AD SDK callback, I wrote one in the classification, resulting in the classification (headline) callback method, overwrite this class (general) callback method, because the method name and parameter are exactly the same, incidentally 😿, although the parameter type is different.

Add: The classification does not override the methods of the main class with the same name, only that the methods of the Category are placed first in the list of methods, and the methods of the main class are moved down the list of methods.

I was going to use the Runtime method swap to retrieve the original method from the list of methods, so that I can call it, but I found that each time the swap, also can not solve the problem, method code is as follows:

-(void) exchangeMainCategoryMethod:(id)target selector:(SEL)selector{ // Get the class method list uint count; Method *methodList = class_copyMethodList([target class], &count); Method firstMethod = nil ; Method lastMethod = nil ; for (int i = 0; i < count; i++) { Method method = methodList[i]; NSLog(@"Category catch selector : %d %@", i, NSStringFromSelector(method_getName(method))); SEL name = method_getName(method); if (name == selector) { if(! firstMethod){ firstMethod = method ; lastMethod = method ; }else{ lastMethod = method ; } } } if(firstMethod && lastMethod && firstMethod! =lastMethod){ method_exchangeImplementations(firstMethod, lastMethod) ; }}Copy the code

The runtime method is also used interchangeover. Declare a familiar advCallBack_isGDT(default NO) in the singleton, exposing two methods: get the value of the attribute and modify the value of the attribute. When the App is started, the default value is NO, because at this time, the headline callback method in the classification is widely clicked in the main class before the callback method is widely clicked, and the pseudo-code is as follows:

case GDT:{ if(! [USER_MANAGER getAdvCallback_isGDT]) { [self changeCallbackMethodToGDT:YES]; } // Initiate AD request code} break; case JRTT:{ if([USER_MANAGER getAdvCallback_isGDT]) { [self changeCallbackMethodToGDT:NO]; }} - / / a headline advertising request code (void) changeCallbackMethodToGDT changeToGDT: (BOOL) {/ / runtime processing, the headlines in the classification of the callback method and the GDT name repetition, Overwrite GDT callback methods [self exchangeMainCategoryMethod: self selector: @ the selector (nativeExpressAdSuccessToLoad: views:)]; [self exchangeMainCategoryMethod:self selector:@selector(nativeExpressAdViewRenderSuccess:)]; [USER_MANAGER setAdvCallback_isGDT:changeToGDT]; }Copy the code