JJException icon indicating copy to clipboard operation
JJException copied to clipboard

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

Open BigPiece opened this issue 3 years ago • 0 comments

如题: 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; }

BigPiece avatar Jul 08 '21 03:07 BigPiece