gpt4 book ai didi

iphone - 我有一个在后台播放音频的 iPad 应用程序,但应用程序图标没有出现在 ipod 控件中

转载 作者:行者123 更新时间:2023-11-29 11:14:28 24 4
gpt4 key购买 nike

我的问题是 - 当我的 iPad 在后台播放音频时,“我的应用程序图标”没有出现。我正在使用 iPodMusicPlayer。为了在后台播放音频,我编写了这些代码..

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
}

- (void)viewWillDisappear:(BOOL)animated
{
[[UIApplication sharedApplication] endReceivingRemoteControlEvents];
[self resignFirstResponder];
[super viewWillDisappear:animated];
}

- (BOOL)canBecomeFirstResponder {
return YES;
}

//当应用程序处于后台时,iPod 控件将发送这些事件

- (void) remoteControlReceivedWithEvent: (UIEvent *) receivedEvent {
if (receivedEvent.type == UIEventTypeRemoteControl) {
switch (receivedEvent.subtype) {

case UIEventSubtypeRemoteControlTogglePlayPause:
[self performSelector:@selector(playPause:)];
break;

case UIEventSubtypeRemoteControlPreviousTrack:
//[self previousSong:nil];
//[self performSelector:@selector(previousSong:)];
break;

case UIEventSubtypeRemoteControlNextTrack:
//[self performSelector:@selector(nextSong:)];
break;
default:
break;
}
}
}

和 info.plist 我也设置了“所需的背景模式”

最佳答案

您还必须将 UIBackgroundModes 添加到您的 Info.plist 并将其值设置为 audio

请查看 iOS 应用程序编程指南,特别是 App States and Multitasking section有关如何在后台执行任务的详细信息。

[更新]

同时将这两行添加到 application:didFinishLaunchingWithOptions: 中的 AppDelegate.m:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];

当您开始播放音频时,这段代码:

UIBackgroundTaskIdentifier newTaskId = UIBackgroundTaskInvalid;
[_player play];
newTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];

这应该可以做到。在模拟器和设备上进行了测试。

关于iphone - 我有一个在后台播放音频的 iPad 应用程序,但应用程序图标没有出现在 ipod 控件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10084800/

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