Open BigPiece opened 3 years ago
如题: NSKeyValueObservingOptions opts = NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew; [self.player addObserver:self forKeyPath:@"rate" options:opts context:nil];
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; }
- (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; }
如题:
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; }