ARC
iOS8.0+
To Avoid the classes out of bounds :
NSString
NSArray
NSDictionary
NSSet
NSCache
NSUserDefaults
NSData
NSAttributedString
also , avoid unrecognized selector sent to instance
crash by user customize.
$ pod 'FFExtension'
You need import one head file just like import <FFManager.h>
.
Then put the code below in your project, maybe in application:didFinishLaunchingWithOptions:
method, make sure the calss will not dealloc in all app life.
__weak typeof(self) weakSelf = self;
[[FFManager sharedInstance] startWorkWithOption:FFHookOptionAll unrecogziedSelectorClassPrefixs:@[@"SSZ"] callBackBlock:^(NSDictionary *exceptionDic) {
[weakSelf reportExecptionToBugly:exceptionDic];
}];
just like this:
#pragma mark - Report Exception To Bugly
- (void)reportExecptionToBugly:(NSDictionary *)exceptionDic
{
if (exceptionDic) {
NSString *name = [exceptionDic objectForKey:FF_Name];
NSString *reason = [exceptionDic objectForKey:FF_Reason];
NSDictionary *extraDic = [exceptionDic objectForKey:FF_ExtraDic];
NSArray *callStack = [exceptionDic objectForKey:FF_CallStackSymbols];
[Bugly reportExceptionWithCategory:3 name:name reason:reason callStack:callStack extraInfo:extraDic terminateApp:NO];
}
}
Tips
: classPrefixs is your own calsses that you want to avoid unrecogzied selector sent to instance
crash.
- (void)startWorkWithOption:(FFHookOption)option unrecogziedSelectorClassPrefixs:(NSArray<NSString *> *)classPrefixs callBackBlock:(FFExceptionBlock)block;
Safe method for example
NSArray
- (BOOL)writeToURL:(NSURL *)url error:(NSError * _Nullable __autoreleasing *)error;
- (id)objectAtIndexedSubscript:(NSUInteger)index;
- (id)objectAtIndexedSubscriptArrayM:(NSUInteger)index;
- (id)objectAtIndex:(NSUInteger)index;
- (instancetype)initWithObjects:(const id _Nonnull [_Nullable])objects count:(NSUInteger)cnt;
- (NSArray *)arrayByAddingObject:(id)anObject;
- (void)getObjects:(id _Nonnull __unsafe_unretained [_Nonnull])objects range:(NSRange)range;
- (NSUInteger)indexOfObject:(id)anObject inRange:(NSRange)range;
- (NSUInteger)indexOfObjectIdenticalTo:(id)anObject inRange:(NSRange)range;
- (NSArray *)subarrayWithRange:(NSRange)range;
- (NSArray *)objectsAtIndexes:(NSIndexSet *)indexes;
- (void)insertObject:(id)anObject atIndex:(NSUInteger)index;
- (void)removeObjectsInRange:(NSRange)range;
- (void)removeObjectsAtIndexes:(NSIndexSet *)indexes;
- (void)removeObject:(id)anObject inRange:(NSRange)range;
- (void)removeObjectAtIndex:(NSUInteger)index;
- (void)removeObjectAtIndexArrayM:(NSUInteger)index;
- (void)replaceObjectAtIndex:(NSUInteger)index withObject:(id)anObject;
- (void)exchangeObjectAtIndex:(NSUInteger)idx1 withObjectAtIndex:(NSUInteger)idx2;
- (void)removeObjectIdenticalTo:(id)anObject inRange:(NSRange)range;
- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx;
- (void)replaceObjectsInRange:(NSRange)range withObjectsFromArray:(NSArray *)otherArray;
- (void)replaceObjectsInRange:(NSRange)range withObjectsFromArray:(NSArray *)otherArray range:(NSRange)otherRange;
- (void)insertObjects:(NSArray *)objects atIndexes:(NSIndexSet *)indexes;
- (void)replaceObjectsAtIndexes:(NSIndexSet *)indexes withObjects:(NSArray *)objects;
and so on ...
By use method swizzle
to do this , no try-catch
.
Have a nice day !