iOS 應(yīng)用在手動kill進程時理澎,卻再次調(diào)用了main函數(shù)的初始化,進而調(diào)用了AppDelegate的相關(guān)方法曙寡,進一步調(diào)用了部分頁面的生命周期糠爬;
現(xiàn)象:app啟動時沒有調(diào)用部分接口,而是kill進程時調(diào)用了举庶,再一些業(yè)務(wù)場景內(nèi)是不能滿足業(yè)務(wù)需求的
排查原因如下:
app的通知角標顯示清除功能相關(guān)代碼造成
- (void)bk_clearBadge {
// 注釋iOS11及以上代碼执隧,在iOS11及以上的APP沙盒內(nèi)查看啟動次數(shù)
if (@available(iOS 11.0, *)) {
[UIApplication sharedApplication].applicationIconBadgeNumber = -1;
} else
if (@available(iOS 10.0, *)) {
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.badge = @(-1);
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"clearBadge" content:content trigger:nil];
[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
}];
} else {
UILocalNotification *clearEpisodeNotification = [[UILocalNotification alloc] init];
clearEpisodeNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
clearEpisodeNotification.timeZone = [NSTimeZone systemTimeZone];
clearEpisodeNotification.applicationIconBadgeNumber = -1;
[[UIApplication sharedApplication] scheduleLocalNotification:clearEpisodeNotification];
}
}
在進入后臺時,*- (void)applicationDidEnterBackground:(UIApplication )application; 內(nèi)調(diào)用清除角標時,存在以下2種情況镀琉;
1峦嗤、兼容iOS11及以上的角標重置,不會造成kill應(yīng)用時再次初始化main函數(shù)屋摔;
2烁设、刪除兼容iOS11及以上的角標重置,會造成kill應(yīng)用再次初始化main函數(shù)钓试;
解決方案:如上代碼