MPRemoteCommandCenter多次调用处理程序块,并导致对选择器方法的不必要调用。
下面是代码片段:
MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];
[commandCenter.nextTrackCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent * _Nonnull event) {
NSLog(@"NEXTTTTTT");
return MPRemoteCommandHandlerStatusSuccess;
}];
[commandCenter.previousTrackCommand addTargetWithHandler:^MPRemoteCommandHandlerStatus(MPRemoteCommandEvent * _Nonnull event) {
NSLog(@"PREVIOUSSS");
return MPRemoteCommandHandlerStatusSuccess;
}];当用户在锁定屏幕的情况下单击音乐播放器的下一步或上一步按钮时,会导致多次调用上面的块。
发布于 2016-06-01 02:56:07
该处理程序将在添加时被多次调用,即使它在同一对象上注册了多次。也许您的代码片段被多次调用。
发布于 2016-03-28 17:14:26
看起来你有多个对象的实例,你调用你的代码。如果你每首曲目都有一个新的UIViewController。旧的视图控制器可能仍然存在,并再次调用处理程序。
试着把你的代码放在
- (void)viewDidAppear:(BOOL)animated然后像这样禁用它
- (void)viewWillDisappear:(BOOL)animated {
MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];
[commandCenter.nextTrackCommand removeTarget:self];
[commandCenter.previousTrackCommand removeTarget:self];
}https://stackoverflow.com/questions/36098934
复制相似问题