ios - How to Hide MPCommandCenter manually?
问题描述
I am currently working on one Podcast app, in which we are using MPCommandCenter to enhance user experience to initialise MPCommandCenter I am using following code
let remoteCommands = MPRemoteCommandCenter.shared()
remoteCommands.playCommand.addTarget { event in
// Perform play action
return .success
}
remoteCommands.pauseCommand.addTarget { event in
// Perform pause action
return .success
}
After using this code MPCommandCenter properly display remote controls. But we have functionality that allow users to Close currently playing podcast. And I am not able to figure out the way to unregister commandcenter manually. Can anyone help me to figure this one out.
解决方案
remoteCommands.playCommand.removeTarget(self)
remoteCommands.pauseCommand.removeTarget(self)
MPNowPlayingInfoCenter.default().nowPlayingInfo = nil
try? AVAudioSession.sharedInstance().setActive(false)
推荐阅读
- spring-boot - 在 Spring Boot 指标中计算 AsyncResponse 调用
- php - Laravel 有时显示 404 not found 页面
- jenkins-pipeline - 我想根据带有项目名称和状态的 jenkins 构建来更改工作流状态
- jquery - JQuery - on() Keyup Validation 不起作用
- qt - 有没有办法在占位符文本 QML 中为特定单词着色?
- python - 为什么我的 on_message 事件打印日志两次?
- spring - 使用 NamedParameterJdbcTemplate 插入批处理并返回完整对象
- cmake - 以非重复方式在 CMake 中设置一堆编译选项
- javascript - 带有 ngModel 的 Textarea 在 ngFor 循环中被覆盖
- c# - 我可以将 EFCore 的 DBContextPool 与 .NET Core 控制台应用程序一起使用吗