TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Nov 2016 |
Maintained by XiaoHange.
一个已经发布到AppStore上的App,最忌讳的就是崩溃问题。为什么在开发阶段或者测试阶段都不会崩溃,而发布到AppStore上就崩溃了呢?究其根源,最主要的原因就是数据的错乱。特别是 服务器返回数据的错乱,将严重影响到我们的App。
可导致崩溃的代码
NSString *nilStr = nil;
NSArray *array = @[@"HaRi", nilStr];
JQSafeKit
to your project.【将JQSafeKit
文件夹中的所有源代码拽入项目中】//这句代码会让JQSafeKit生效,若没有如下代码,则JQSafeKit就不起作用
[JQSafeKit becomeEffective];
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[JQSafeKit becomeEffective];
//监听通知:JQSafeKitNotification, 获取JQSafeKit捕获的崩溃日志的详细信息
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dealwithCrashMessage:) name:JQSafeKitNotification object:nil];
return YES;
}
- (void)dealwithCrashMessage:(NSNotification *)note {
//注意:所有的信息都在userInfo中
//你可以在这里收集相应的崩溃信息进行相应的处理(比如传到自己服务器)
NSLog(@"%@",note.userInfo);
}
1. NSArray的快速创建方式 NSArray *array = @[@"HaRi", @"JQSafeKit"]; //这种创建方式其实调用的是2中的方法
2. +(instancetype)arrayWithObjects:(const id _Nonnull __unsafe_unretained *)objects count:(NSUInteger)cnt
3. - (id)objectAtIndex:(NSUInteger)index
1. - (id)objectAtIndex:(NSUInteger)index
2. - (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx
3. - (void)removeObjectAtIndex:(NSUInteger)index
4. - (void)insertObject:(id)anObject atIndex:(NSUInteger)index
1. NSDictionary的快速创建方式 NSDictionary *dict = @{@"frameWork" : @"JQSafeKit"}; //这种创建方式其实调用的是2中的方法
2. +(instancetype)dictionaryWithObjects:(const id _Nonnull __unsafe_unretained *)objects forKeys:(const id<NSCopying> _Nonnull __unsafe_unretained *)keys count:(NSUInteger)cnt
1. - (void)setObject:(id)anObject forKey:(id<NSCopying>)aKey
2. - (void)removeObjectForKey:(id)aKey
1. - (unichar)characterAtIndex:(NSUInteger)index
2. - (NSString *)substringFromIndex:(NSUInteger)from
3. - (NSString *)substringToIndex:(NSUInteger)to {
4. - (NSString *)substringWithRange:(NSRange)range {
5. - (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement
6. - (NSString *)stringByReplacingOccurrencesOfString:(NSString *)target withString:(NSString *)replacement options:(NSStringCompareOptions)options range:(NSRange)searchRange
7. - (NSString *)stringByReplacingCharactersInRange:(NSRange)range withString:(NSString *)replacement
1. 由于NSMutableString是继承于NSString,所以这里和NSString有些同样的方法就不重复写了
2. - (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)aString
3. - (void)insertString:(NSString *)aString atIndex:(NSUInteger)loc
4. - (void)deleteCharactersInRange:(NSRange)range
1.- (instancetype)initWithString:(NSString *)str
2.- (instancetype)initWithAttributedString:(NSAttributedString *)attrStr
3.- (instancetype)initWithString:(NSString *)str attributes:(NSDictionary<NSString *,id> *)attrs
1.- (instancetype)initWithString:(NSString *)strutableString是继承于NSString,所以这里和NSString有些同样的方法就不重复写了
2.- (instancetype)initWithString:(NSString *)str attributes:(NSDictionary<NSString *,id> *)attrs
1.- (void)setValue:(id)value forKey:(NSString *)key
2.- (void)setValue:(id)value forKeyPath:(NSString *)keyPath
3.- (void)setValue:(id)value forUndefinedKey:(NSString *)key //这个方法一般用来重写,不会主动调用
4.- (void)setValuesForKeysWithDictionary:(NSDictionary<NSString *,id> *)keyedValue