liuslevis / gybootingprotection Goto Github PK
View Code? Open in Web Editor NEWA tool for detecting and repairting continuous launch crash of iOS App
License: MIT License
A tool for detecting and repairting continuous launch crash of iOS App
License: MIT License
/**
* 对于代码构建 UI 的项目一般在 didFinishLaunch 方法中初始化 window,
* 想在 swizzling 方法中 present alertController 需要自己先初始化 window 并提供一个 rootViewController
*/
- (void)presentAlertViewController:(UIAlertController *)alertController {
if (![self hasStoryboardInfo]) {
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = [[UIViewController alloc] init];
}
[self.window makeKeyAndVisible];
[self.window.rootViewController presentViewController:alertController animated:YES completion:nil];
}
使用storyboard构建的window,在presentAlertViewController的时候 [self.window makeKeyAndVisible]就把window展示出来了,导致rootViewController被初始化,业务代码就被执行了,而且,如果是使用storyboard构建的window,我们无法掌控这个window什么时候被初始化,建议使用者手动初始化window
RT
经考察,发现支付宝的sdk 也对AppDelegate swizzle了。
有解决办法吗?
思路很好,很轻量级。有个实现上可以优化下,可以降低50%以上误报机率,监听用户手动划掉APP这个事件,其中一些特定场景,是可以获取的。另外对API设计的建议。
用户主动kill掉APP分为两种情况:
第一种场景更为常见,可以通过监听UIApplicationWillTerminateNotification
来捕获该动作,捕获后恢复计数。第二种情况,无法监听到。但也足以降低50%以上的误报机率。
该机制当前所处的状态,比如:NeedFix 、isFixing,建议用枚举来做为API透出。比如:
typedef NS_ENUM(NSInteger, BootingProtectionStatus) {
BootingProtectionStatusNormal, /**< APP 启动正常 */
BootingProtectionStatusNormalChecking, /**< 正在检测是否会在特定时间内是否会 Crash,注意:检测状态下“连续启动崩溃计数”个数小于或等于上限值 */
BootingProtectionStatusNeedFix, /**< APP 出现连续启动 Crash,需要采取修复措施 */
BootingProtectionStatusFixing, /**< APP 出现连续启动 Crash,正在修复中... */
};
/*!
* 当前启动Crash的状态
*/
@property (nonatomic, assign, readonly) ABSBootingProtectionStatus bootingProtectionStatus;
/*!
* 达到需要执行上报操作的“连续启动崩溃计数”个数。
*/
@property (nonatomic, assign, readonly) NSUInteger continuousCrashOnLaunchNeedToReport;
/*!
* 达到需要执行修复操作的“连续启动崩溃计数”个数。
*/
@property (nonatomic, assign, readonly) NSUInteger continuousCrashOnLaunchNeedToFix;
/*!
* APP 启动后经过多少秒,可以将“连续启动崩溃计数”清零
*/
@property (nonatomic, assign, readonly) NSTimeInterval crashOnLaunchTimeIntervalThreshold;
reportBlock
上报逻辑,
repairtBlock
修复逻辑
typedef void (^BoolCompletionHandler)(BOOL succeeded, NSError *error);
typedef void (^RepairBlock)(ABSBoolCompletionHandler completionHandler);
用户执行 BoolCompletionHandler
后即可知道是否执行完毕,并且支持异步操作。
异步操作带来的问题,可以通过前面提到的枚举API来实时监测状态,来决定各种其他操作。
delete Library Directory maybe cause NSUserDefault damage
如果项目是使用纯代码构建 UI 的话,一般需要在-application:didFinishLaunchingWithOptions:
方法中初始化window
和rootViewController
,用 swizzling 替换了该方法来处理 crash 是可以的,但如果要给用户一个提示框之后再处理的话就不好用UIAlertViewController
了,[self.window.rootViewController presentViewController:alertController animated:YES completion:nil]
的时候self.window.rootViewController
还是nil
。针对这种情况最好能在文档中给出说明呢。
整体思路很棒,多谢分享🙏
替换didFinishLaunchingWithOptions
能检查出crash,但是applicationDidBecomeActive
还是会正常执行,如果applicationDidBecomeActive
中有代码crash了,那么永远看不到这个alert提示
登录状态下,打开app就连续crash
修复,重新登录
再次crash。。。
GG
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.