MPRemoteCommandCenter在iOS中多次调用处理程序

MPRemoteCommandCenter在iOS中多次调用处理程序,第1张

概述MPRemoteCommandCenter多次调用处理程序块,并导致对选择器方法的不必要调用. 这是代码片段: MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];[commandCenter.nextTrackCommand addTargetWithHandler:^MPRem 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;}];

当用户在屏幕锁定时点击音乐播放器底座上的下一个或上一个按钮时,会多次调用上述块.

解决方法 看起来你有多个你调用代码的对象实例,例如.如果您按轨道推送新的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中多次调用处理程序所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1108187.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存