背景
老是有莫名其妙的地方在修改我的邏輯,但是代碼search找不出來(lái),所以準(zhǔn)備直接看看是哪兒調(diào)用的,因?yàn)槭窍到y(tǒng)的方法,所以準(zhǔn)備用method_exchange
需要替換的方法
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
首先交換方法
Method orig_method = nil, alt_method = nil;
SEL orig_sel = @selector(setIdleTimerDisabled:);
SEL alt_sel = @selector(kk_setIdleTimerDisabled:);
// First, look for the methods
orig_method = class_getInstanceMethod([UIApplication class], orig_sel);
alt_method = class_getInstanceMethod([UIApplication class], alt_sel);
// If both are found, swizzle them
if ((orig_method != nil) && (alt_method != nil)) {
method_exchangeImplementations(orig_method, alt_method);
}
實(shí)現(xiàn)一個(gè)分類
@interface UIApplication(KKUIDebug)
- (void)kk_setIdleTimerDisabled:(BOOL)idle;
@end
@implementation UIApplication (KKUIDebug)
- (void)kk_setIdleTimerDisabled:(BOOL)idle
{
[self kk_setIdleTimerDisabled:idle];
}
@end