gpt4 book ai didi

ios - MPMusicPlayerControllerPlaybackStateDidChangeNotification 在后台

转载 作者:行者123 更新时间:2023-11-29 00:41:58 27 4
gpt4 key购买 nike

每当我播放轨道然后移至后台时,我都无法在我的应用程序中触发这些通知。有谁知道为什么或如何?

        self.player = [MPMusicPlayerController applicationMusicPlayer];
[self.player beginGeneratingPlaybackNotifications];


[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handlePlaybackStateChanged:) name:MPMusicPlayerControllerPlaybackStateDidChangeNotification object:self.player ];


[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleItemChanged:) name:MPMusicPlayerControllerNowPlayingItemDidChangeNotification object:self.player ];

最佳答案

添加以下代码

UIBackgroundTaskIdentifier bgTask = 0;
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];

在您的 AppDelegate 的 applicationDidEnterBackground 方法中,那么您的方法也将在 BackGround 中工作。

同时启用

Audio, Airplay and Picture in Picture

来自能力。看截图

enter image description here

关于ios - MPMusicPlayerControllerPlaybackStateDidChangeNotification 在后台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39231708/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com