push时偶尔会重复多个页面的保护(iOS开发)

+(void)load{

MethodpushMethod =class_getInstanceMethod([selfclass],@selector(pushViewController:animated:));

MethodtoMethod =class_getInstanceMethod([selfclass],@selector(securePush:animated:));

if(!class_addMethod([selfclass],@selector(pushViewController:animated:),method_getImplementation(toMethod),method_getTypeEncoding(toMethod))) {

method_exchangeImplementations(pushMethod, toMethod);

}

}

-(void)securePush:(UIViewController*)viewController animated:(BOOL)isYesOrNo{

NSString* viewControllerStr = [NSStringstringWithFormat:@"%@",[viewControllerclass]];

NSLog(@"\nviewControllerStr:%@\n",viewControllerStr);

NSUserDefaults* defaults = [NSUserDefaultsstandardUserDefaults];

[defaultssetObject:viewControllerStrforKey:@"currentViewController"];

[defaultssynchronize];

NSString*topViewController =NSStringFromClass([self.topViewControllerclass]);

NSString*targetViewController =NSStringFromClass(viewController.class);

NSLog(@"topViewController:%@\ntargetViewController:%@",topViewController,targetViewController);

if([topViewControllerisEqualToString:targetViewController]) {

return;

}

[selfsecurePush:viewControlleranimated:isYesOrNo];

}

你可能感兴趣的:(push时偶尔会重复多个页面的保护(iOS开发))