Skip to content

Commit d08a4b1

Browse files
author
李杰
committed
fix AMAP kvo bug #42
1 parent 93c40bd commit d08a4b1

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

JJException/Source/MRC/NSObject+KVOCrash.m

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ + (void)jj_swizzleKVOCrash{
220220
}
221221

222222
- (void)hookAddObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context{
223-
if (object_getClass(observer) == objc_getClass("RACKVOProxy")) {
223+
if ([self ignoreKVOInstanceClass:observer]) {
224224
[self hookAddObserver:observer forKeyPath:keyPath options:options context:context];
225225
return;
226226
}
@@ -268,7 +268,7 @@ - (void)hookAddObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath opti
268268
}
269269

270270
- (void)hookRemoveObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath context:(void*)context{
271-
if (object_getClass(observer) == objc_getClass("RACKVOProxy")) {
271+
if ([self ignoreKVOInstanceClass:observer]) {
272272
[self hookRemoveObserver:observer forKeyPath:keyPath context:context];
273273
return;
274274
}
@@ -277,7 +277,7 @@ - (void)hookRemoveObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath c
277277
}
278278

279279
- (void)hookRemoveObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath{
280-
if (object_getClass(observer) == objc_getClass("RACKVOProxy")) {
280+
if ([self ignoreKVOInstanceClass:observer]) {
281281
[self hookRemoveObserver:observer forKeyPath:keyPath];
282282
return;
283283
}
@@ -307,6 +307,32 @@ - (void)hookRemoveObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath{
307307
[item release];
308308
}
309309

310+
/**
311+
Ignore Special Library
312+
313+
@param object Instance Class
314+
@return YES or NO
315+
*/
316+
- (BOOL)ignoreKVOInstanceClass:(id)object{
317+
318+
if (!object) {
319+
return NO;
320+
}
321+
322+
//Ignore ReactiveCocoa
323+
if (object_getClass(object) == objc_getClass("RACKVOProxy")) {
324+
return YES;
325+
}
326+
327+
//Ignore AMAP
328+
NSString* className = NSStringFromClass(object_getClass(object));
329+
if ([className hasPrefix:@"AMap"]) {
330+
return YES;
331+
}
332+
333+
return NO;
334+
}
335+
310336

311337
/**
312338
* Hook the kvo object dealloc and to clean the kvo array

0 commit comments

Comments
 (0)