美文网首页iOS 收集
push时偶尔会重复多个页面的保护(iOS开发)

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

作者: 孤居引 | 来源:发表于2018-08-15 15:39 被阅读2次

+(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开发)

    本文链接:https://www.haomeiwen.com/subject/hufthttx.html