
这是代码片段:
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;}]; 当用户在屏幕锁定时点击音乐播放器底座上的下一个或上一个按钮时,会多次调用上述块.
解决方法 看起来你有多个你调用代码的对象实例,例如.如果您按轨道推送新的UIVIEwController.旧视图控制器可能仍然存在并再次调用处理程序.尝试将代码放入
- (voID)vIEwDIDAppear:(BOol)animated
然后像这样禁用它
- (voID)vIEwWilldisappear:(BOol)animated { MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter]; [commandCenter.nextTrackCommand removeTarget:self]; [commandCenter.prevIoUsTrackCommand removeTarget:self];} 总结 以上是内存溢出为你收集整理的MPRemoteCommandCenter在iOS中多次调用处理程序全部内容,希望文章能够帮你解决MPRemoteCommandCenter在iOS中多次调用处理程序所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)