jezzmemo / JJException

Protect the objective-c application(保护App不闪退)
MIT License
1.63k stars 268 forks source link

KVO开启防护后,AVPlayer 添加observer的options如果有 initial值,则添加observer不成功 #107

Open BigPiece opened 3 years ago

BigPiece commented 3 years ago

如题: NSKeyValueObservingOptions opts = NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew; [self.player addObserver:self forKeyPath:@"rate" options:opts context:nil];

添加后查看player.observationInfo 是null空的,其他的类型如果添加了NSKeyValueObservingOptionInitial值,还没试是否会添加失败。

在KVO防护里判断下如果有intial值的不防护,问题可以解决 - (void)hookAddObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context{ if ([self ignoreKVOInstanceClass:observer] || (options & NSKeyValueObservingOptionInitial)) { [self hookAddObserver:observer forKeyPath:keyPath options:options context:context]; return; }