Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
BigPiece opened this issue Jul 8, 2021 · 0 comments

Comments

@BigPiece
Copy link

BigPiece commented Jul 8, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant