WF: _WebFilterIsActive returning: NO并且Can't Add Self as Subview 崩潰解決辦法

錯(cuò)誤提示如下:

 WF: _userSettingsForUser mobile: {
filterBlacklist =     (
);
filterWhitelist =     (
);
restrictWeb = 1;
useContentFilter = 0;
useContentFilterOverrides = 0;
whitelistEnabled = 0;
}

WF: _WebFilterIsActive returning: NO
WF: _userSettingsForUser mobile: {
filterBlacklist =     (
);
filterWhitelist =     (
);
restrictWeb = 1;
useContentFilter = 0;
useContentFilterOverrides = 0;
whitelistEnabled = 0;
}
 WF: _WebFilterIsActive returning: NO
 [Bugly]  Trapped uncaught exception  'NSInvalidArgumentException', reason: 'Can't add self as subview' `

這段可以跳過,是我問題出現(xiàn)的方式:
(程序啟動(dòng)后术浪,快速的點(diǎn)擊屏幕瓢对,因?yàn)橛幸粋€(gè)廣告頁,會(huì)跳轉(zhuǎn)廣告頁胰苏,但是在跳轉(zhuǎn)廣告頁之前硕蛹,我會(huì)先切換程序的根控制器,在延時(shí)1秒跳轉(zhuǎn)廣告詳情頁硕并,這時(shí)會(huì)顯示程序的首頁法焰,首頁我做了緩存處理,正好點(diǎn)擊的位置是首頁的滾動(dòng)廣告倔毙,這時(shí)又跳轉(zhuǎn)一個(gè)廣告頁埃仪,最終的結(jié)果是只跳轉(zhuǎn)了時(shí)候首頁的廣告,但是點(diǎn)擊返回的時(shí)候陕赃,無法返回卵蛉,并崩潰,報(bào)如上錯(cuò)誤C纯狻)

現(xiàn)在說一下這個(gè)排查思路:

  1. 拿這些打印去找度娘傻丝,首先我拿的是WF: _WebFilterIsActive returning: NO ,(為啥拿這段诉儒,因?yàn)檫@個(gè)打印我沒見過葡缰,比較特殊,我一般都是拿那些不常見的打印去查忱反,你也可以這樣)运准,搜索出來的結(jié)果其中一個(gè)鏈接,問題的矛頭都指向了UIWebview缭受,
    AA4A486A-4573-4241-801E-777D6FD7805F.png

    解決辦法也很簡單胁澳,就是把UIWebView更換為WKWebView,我當(dāng)然按照文檔的指示米者,換好之后韭畸,繼續(xù)測試,發(fā)現(xiàn)問題還是存在
  2. 既然問題還存在蔓搞,說明不是UIWebView的問題胰丁,我把關(guān)注點(diǎn)放在 'Can't add self as subview'這句話上,查下來的結(jié)果認(rèn)為是連續(xù)push兩個(gè)控制器導(dǎo)致喂分,這和我的問題是吻合的锦庸,直接按照文檔的指示開始操作,鏈接
    我其實(shí)也看其他人寫的了蒲祈,對(duì)于我來說改起來比較麻煩甘萧,這個(gè)是最簡單的辦法萝嘁,運(yùn)用了運(yùn)行時(shí)!

現(xiàn)在問題完美的解決了扬卷,我也把自己的代碼分享出來牙言,希望幫助遇到同樣問題的你!
下面貼上代碼怪得!

  1. 首先創(chuàng)建一個(gè)分類(分類名為UINavigationController+SafePushing咱枉,可以隨便起哈)
  2. 復(fù)制下面的代碼到.m文件
  3. 創(chuàng)建UINavigationController的時(shí)候引入分類
    大功告成!
#import "UINavigationController+SafePushing.h"
#import <objc/runtime.h>




/// This char is used to add storage for the isPushingViewController property.
static char const * const ObjectTagKey = "ObjectTag";

@interface UINavigationController ()<UINavigationControllerDelegate>
@property (readwrite,getter = isViewTransitionInProgress) BOOL viewTransitionInProgress;
@end

@implementation UINavigationController (SafePushing)
- (void)setViewTransitionInProgress:(BOOL)property {
NSNumber *number = [NSNumber numberWithBool:property];
objc_setAssociatedObject(self, ObjectTagKey, number , OBJC_ASSOCIATION_RETAIN);
}

- (BOOL)isViewTransitionInProgress {
NSNumber *number = objc_getAssociatedObject(self, ObjectTagKey);
return [number boolValue];
}

#pragma mark - Intercept Pop, Push, PopToRootVC
/// @name Intercept Pop, Push, PopToRootVC
- (NSArray *)safePopToRootViewControllerAnimated:(BOOL)animated {
if (self.viewTransitionInProgress) return nil;
if (animated) {
    self.viewTransitionInProgress = YES;
}
//-- This is not a recursion, due to method swizzling the call below calls the original  method.
return [self safePopToRootViewControllerAnimated:animated];
}

- (NSArray *)safePopToViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (self.viewTransitionInProgress) return nil;
if (animated) {
    self.viewTransitionInProgress = YES;
}
//-- This is not a recursion, due to method swizzling the call below calls the original  method.
return [self safePopToViewController:viewController animated:animated];
}

- (UIViewController *)safePopViewControllerAnimated:(BOOL)animated {
if (self.viewTransitionInProgress) return nil;
if (animated) {
    self.viewTransitionInProgress = YES;
}
//-- This is not a recursion, due to method swizzling the call below calls the original  method.
return [self safePopViewControllerAnimated:animated];
}

- (void)safePushViewController:(UIViewController *)viewController animated:(BOOL)animated {
self.delegate = self;
//-- If we are already pushing a view controller, we dont push another one.
if (self.isViewTransitionInProgress == NO) {
    //-- This is not a recursion, due to method swizzling the call below calls the original  method.
    [self safePushViewController:viewController animated:animated];
    if (animated) {
        self.viewTransitionInProgress = YES;
    }
}
}

// This is confirmed to be App Store safe.
// If you feel uncomfortable to use Private API, you could also use the delegate method navigationController:didShowViewController:animated:.
- (void)safeDidShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
//-- This is not a recursion. Due to method swizzling this is calling the original method.
[self safeDidShowViewController:viewController animated:animated];
self.viewTransitionInProgress = NO;
}


// If the user doesnt complete the swipe-to-go-back gesture, we need to intercept it and set the flag to NO again.
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
id<UIViewControllerTransitionCoordinator> tc = navigationController.topViewController.transitionCoordinator;
[tc notifyWhenInteractionEndsUsingBlock:^(id<UIViewControllerTransitionCoordinatorContext> context) {
    self.viewTransitionInProgress = NO;
    //--Reenable swipe back gesture.
    self.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)viewController;
    [self.interactivePopGestureRecognizer setEnabled:YES];
}];
//-- Method swizzling wont work in the case of a delegate so:
//-- forward this method to the original delegate if there is one different than ourselves.
if (navigationController.delegate != self) {
    [navigationController.delegate navigationController:navigationController
                                 willShowViewController:viewController
                                               animated:animated];
}
}

+ (void)load {
//-- Exchange the original implementation with our custom one.
method_exchangeImplementations(class_getInstanceMethod(self, @selector(pushViewController:animated:)), class_getInstanceMethod(self, @selector(safePushViewController:animated:)));
//    method_exchangeImplementations(class_getInstanceMethod(self, @selector(didShowViewController:animated:)), class_getInstanceMethod(self, @selector(safeDidShowViewController:animated:)));
method_exchangeImplementations(class_getInstanceMethod(self, @selector(popViewControllerAnimated:)), class_getInstanceMethod(self, @selector(safePopViewControllerAnimated:)));
method_exchangeImplementations(class_getInstanceMethod(self, @selector(popToRootViewControllerAnimated:)), class_getInstanceMethod(self, @selector(safePopToRootViewControllerAnimated:)));
method_exchangeImplementations(class_getInstanceMethod(self, @selector(popToViewController:animated:)), class_getInstanceMethod(self, @selector(safePopToViewController:animated:)));
}


@end
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末徒恋,一起剝皮案震驚了整個(gè)濱河市蚕断,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌入挣,老刑警劉巖亿乳,帶你破解...
    沈念sama閱讀 219,490評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異财岔,居然都是意外死亡风皿,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,581評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門匠璧,熙熙樓的掌柜王于貴愁眉苦臉地迎上來桐款,“玉大人,你說我怎么就攤上這事夷恍∧д#” “怎么了?”我有些...
    開封第一講書人閱讀 165,830評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵酿雪,是天一觀的道長遏暴。 經(jīng)常有香客問我,道長指黎,這世上最難降的妖魔是什么朋凉? 我笑而不...
    開封第一講書人閱讀 58,957評(píng)論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮醋安,結(jié)果婚禮上杂彭,老公的妹妹穿的比我還像新娘。我一直安慰自己吓揪,他們只是感情好亲怠,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,974評(píng)論 6 393
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著柠辞,像睡著了一般团秽。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,754評(píng)論 1 307
  • 那天习勤,我揣著相機(jī)與錄音踪栋,去河邊找鬼。 笑死姻报,一個(gè)胖子當(dāng)著我的面吹牛己英,可吹牛的內(nèi)容都是我干的间螟。 我是一名探鬼主播吴旋,決...
    沈念sama閱讀 40,464評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼厢破!你這毒婦竟也來了荣瑟?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,357評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤摩泪,失蹤者是張志新(化名)和其女友劉穎笆焰,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體见坑,經(jīng)...
    沈念sama閱讀 45,847評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡嚷掠,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,995評(píng)論 3 338
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了荞驴。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片不皆。...
    茶點(diǎn)故事閱讀 40,137評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖熊楼,靈堂內(nèi)的尸體忽然破棺而出霹娄,到底是詐尸還是另有隱情,我是刑警寧澤鲫骗,帶...
    沈念sama閱讀 35,819評(píng)論 5 346
  • 正文 年R本政府宣布犬耻,位于F島的核電站,受9級(jí)特大地震影響执泰,放射性物質(zhì)發(fā)生泄漏枕磁。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,482評(píng)論 3 331
  • 文/蒙蒙 一术吝、第九天 我趴在偏房一處隱蔽的房頂上張望计济。 院中可真熱鬧,春花似錦顿苇、人聲如沸峭咒。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,023評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽凑队。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間漩氨,已是汗流浹背西壮。 一陣腳步聲響...
    開封第一講書人閱讀 33,149評(píng)論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留叫惊,地道東北人款青。 一個(gè)月前我還...
    沈念sama閱讀 48,409評(píng)論 3 373
  • 正文 我出身青樓,卻偏偏與公主長得像霍狰,于是被迫代替她去往敵國和親抡草。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,086評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫蔗坯、插件康震、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 12,109評(píng)論 4 62
  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,185評(píng)論 25 707
  • 在正式分手的那天腿短,我問他是不是在耍我,至始至終绘梦。 他說橘忱,他和我在一起的時(shí)候是真的喜歡我的,但是我要他說他愛我卸奉,但是...
    81c149c5e10e閱讀 156評(píng)論 0 0
  • 本書中钝诚,作者威廉·德雷謝維奇批評(píng)了精英教育,指出常春藤院校已經(jīng)忘記了教育的本質(zhì)择卦,正在培養(yǎng)大批過度自信卻輸不...
    書春閱讀 641評(píng)論 0 2
  • 你有沒有特別怕的事情 我有 特別怕自己懶 怕自己不努力 怕以后因?yàn)楝F(xiàn)在的懶和不努力而后悔敲长。 我也知道 怕是沒有用的
    黃小仙兒她會(huì)發(fā)光i閱讀 190評(píng)論 0 0