Skip to content

Commit

Permalink
1.20更新
Browse files Browse the repository at this point in the history
1:添加type,可以根据type启用不同的crash 拦截
2:添加回调,可以获取拦截crash 信息
  • Loading branch information
hongru1227 committed Aug 24, 2017
1 parent d0529d2 commit 854e1d1
Show file tree
Hide file tree
Showing 28 changed files with 158 additions and 604 deletions.
6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- JRSwizzle (1.0)
- WTSafeGuard (1.0.4):
- WTSafeGuard (1.2.0):
- JRSwizzle

DEPENDENCIES:
Expand All @@ -12,8 +12,8 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
JRSwizzle: dd5ead5d913a0f29e7f558200165849f006bb1e3
WTSafeGuard: bb1688e3a023e293f5c3c0690af43b1518fd2790
WTSafeGuard: 2be47b7e670d246cff66f3c5084bbce177602f04

PODFILE CHECKSUM: f38df40f5d74089817f4f9d44c4669ee3c39834a

COCOAPODS: 1.3.0.beta.2
COCOAPODS: 1.3.1
12 changes: 11 additions & 1 deletion Example/WTSafeGuard/WTAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@
//

#import "WTAppDelegate.h"

#import "WTSafeGuard.h"
@interface WTAppDelegate()<WTSafeGuardDelegate>
@end
@implementation WTAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[WTSafeGuard startSafeGuardWithType:WTSafeGuardType_NilTarget| WTSafeGuardType_Foundation];
[WTSafeGuard shareInstance].delegate = self;
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[dic setObject:nil forKey:nil];
return YES;
}

Expand Down Expand Up @@ -43,4 +49,8 @@ - (void)applicationWillTerminate:(UIApplication *)application
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

- (void)safeGuardCrashMessage:(NSString *)className selector:(NSString *)selector stack:(NSArray *)stack
{

}
@end
4 changes: 2 additions & 2 deletions WTSafeGuard.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'WTSafeGuard'
s.version = '1.1.1'
s.version = '1.2.0'
s.summary = 'A short description of WTSafeGuard.'

# This description is used to generate tags and improve search results.
Expand All @@ -31,7 +31,7 @@ Pod::Spec.new do |s|
s.ios.deployment_target = '8.0'

s.source_files = 'WTSafeGuard/Classes/**/*','WTSafeGuard/Classes/KVO/*','WTSafeGuard/Classes/UI/*',
'WTSafeGuard/Classes/Container/*','WTSafeGuard/Classes/Target/*','WTSafeGuard/Classes/WebView/*','WTSafeGuard/Classes/Timer/*'
'WTSafeGuard/Classes/Container/*','WTSafeGuard/Classes/Target/*','WTSafeGuard/Classes/Timer/*'
# s.resource_bundles = {
# 'WTSafeGuard' => ['WTSafeGuard/Assets/*.png']
# }
Expand Down
15 changes: 0 additions & 15 deletions WTSafeGuard/Classes/Container/NSArray+WTSafe.h

This file was deleted.

80 changes: 0 additions & 80 deletions WTSafeGuard/Classes/Container/NSArray+WTSafe.m

This file was deleted.

2 changes: 1 addition & 1 deletion WTSafeGuard/Classes/Container/NSAttributedString+WTSafe.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ + (void)runSafeGuard
- (NSAttributedString *)WT_safeAttributedSubstringFromRange:(NSRange)range
{
if (range.location > self.length || range.location + range.length > self.length) {
NSAssert(nil, @"WT_safeAttributedSubstringFromRange crash");
[WTSafeGuard updateGuardCrashClassName:NSStringFromClass(self.class) selector:NSStringFromSelector(_cmd)];
return nil;
}

Expand Down
7 changes: 3 additions & 4 deletions WTSafeGuard/Classes/Container/NSDictionary+WTSafe.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ @implementation NSDictionary (WTSafe)
+ (void)runSafeGuard
{
NSError *error = nil;

[NSDictionary jr_swizzleClassMethod:@selector(sharedKeySetForKeys:) withClassMethod:@selector(WT_safeSharedKeySetForKeys:) error:&error];
[WTSafeGuard logSafeMethodErrorThenSetNil:&error];

Expand All @@ -32,7 +31,7 @@ + (void)runSafeGuard
+ (id)WT_safeSharedKeySetForKeys:(NSArray *)keys
{
if (!keys || ![keys isKindOfClass:[NSArray class]]) {
NSAssert(false , @"WT_safeSharedKeySetForKeys crash");
[WTSafeGuard updateGuardCrashClassName:NSStringFromClass(self.class) selector:NSStringFromSelector(_cmd)];
return nil;
}

Expand All @@ -44,7 +43,7 @@ - (instancetype)WT_safeInitWithObjects:(NSArray *)objects forKeys:(NSArray *)key
if(![objects isKindOfClass:[NSArray class]] ||
![keys isKindOfClass:[NSArray class]] ||
objects.count != keys.count) {
NSAssert(false , @"WT_safeInitWithObjects crash");
[WTSafeGuard updateGuardCrashClassName:NSStringFromClass(self.class) selector:NSStringFromSelector(_cmd)];
return nil;
}

Expand All @@ -57,7 +56,7 @@ - (instancetype)WT_safeInitWithObjects:(const id [])objects
{
for (int i = 0; i < cnt; ++i) {
if(!keys[i] || !objects[i]) {
NSAssert(false , @"WT_safeInitWithObjects crash");
[WTSafeGuard updateGuardCrashClassName:NSStringFromClass(self.class) selector:NSStringFromSelector(_cmd)];
return nil;
}
}
Expand Down
3 changes: 2 additions & 1 deletion WTSafeGuard/Classes/Container/NSFileManager+WTSafe.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ + (void)runSafeGuard
NSError *error = nil;
[NSFileManager jr_swizzleMethod:@selector(enumeratorAtURL:includingPropertiesForKeys:options:errorHandler:) withMethod:@selector(WT_safeEnumeratorAtURL:includingPropertiesForKeys:options:errorHandler:) error:&error];
[WTSafeGuard logSafeMethodErrorThenSetNil:&error];

}

#pragma mark - Object Private Function

- (NSDirectoryEnumerator *)WT_safeEnumeratorAtURL:(NSURL *)url includingPropertiesForKeys:(NSArray *)keys options:(NSDirectoryEnumerationOptions)mask errorHandler:(BOOL (^)(NSURL *, NSError *))handler
{
if(!url) {
NSAssert(false, @"WT_safeEnumeratorAtURL crash");
[WTSafeGuard updateGuardCrashClassName:NSStringFromClass(self.class) selector:NSStringFromSelector(_cmd)];
return nil;
}

Expand Down
2 changes: 1 addition & 1 deletion WTSafeGuard/Classes/Container/NSIndexPath+WTSafe.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ + (void)runSafeGuard
- (void)WT_safeGetIndexes:(NSUInteger *)indexes range:(NSRange)positionRange
{
if (positionRange.location + positionRange.length > self.length) {
NSAssert(false , @"WT_safeGetIndexes crash");
[WTSafeGuard updateGuardCrashClassName:NSStringFromClass(self.class) selector:NSStringFromSelector(_cmd)];
return;
}

Expand Down
2 changes: 1 addition & 1 deletion WTSafeGuard/Classes/Container/NSJSONSerialization+WTSafe.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ + (void)runSafeGuard
+ (NSData *)WT_safeDataWithJSONObject:(id)obj options:(NSJSONWritingOptions)opt error:(NSError **)error
{
if (!obj) {
NSAssert(false, @"WT_safeEnumeratorAtURL crash");
[WTSafeGuard updateGuardCrashClassName:NSStringFromClass(self.class) selector:NSStringFromSelector(_cmd)];
return nil;
}

Expand Down
14 changes: 0 additions & 14 deletions WTSafeGuard/Classes/Container/NSMutableArray+WTSafe.h

This file was deleted.

Loading

0 comments on commit 854e1d1

Please sign in to comment.