ios - ios 通话后恢复在后台运行的应用程序

标签 ios background multitasking interruption

我有一个 ios 应用程序,当它进入后台时会继续播放音乐。现在,如果有电话来电,无论是否接听,应用程序都不会恢复播放音乐。 这两天我一直在这里阅读关于这个问题的帖子。他们都没有解决我的问题。

我正在使用 AVQueuePlayer 对象,因为我也在需要时流式传输我的音乐。 现在,自 ios6 以来,委托(delegate)方法已被弃用。所以我正在使用通知。

令人惊奇的是,中断结束(电话结束)被通知,播放音乐的代码也被编写但是应用程序只是在它到达前台之前不播放音乐(有另一个通知)

这是我的代码

 -(void)viewWillAppear
 {.....
  ........
   .....
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioInterruptionNotification:) name:AVAudioSessionInterruptionNotification object:nil];
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(audioInterruptionNotification:) name:UIApplicationDidBecomeActiveNotification object:nil]
}

-(void)audioInterruptionNotification:(NSNotification *) aNotification {

NSLog(@"Interrupt %@", aNotification);
NSDictionary *dict = [aNotification userInfo];
NSUInteger typeKey = [[dict objectForKey:@"AVAudioSessionInterruptionTypeKey"] unsignedIntegerValue]; NSLog(@"%d", typeKey);
if (typeKey == 0)
{
        [avPlayer play];
        NSLog(@"1.......");
  }
else if (typeKey == 1)
{
    [avPlayer play];
    NSLog(@"3...............");

    ;
}

另外,我试过通过调度队列引起延迟。 委托(delegate)方法似乎不起作用。 但 gaana、saavn 和 apple 的官方音乐应用程序在通话后恢复。所以这是可能的。 我似乎错过了什么。 如果我使用核心电话。我将不得不添加一个完整的框架,这将增加应用程序的大小。 如果这是唯一的方法。请告诉如何。

谢谢。我非常感谢你的时间。

最佳答案

所以过了一会儿我回来了,我发现我的问题仍然没有得到解答。好吧,我已经解决了我的问题。 事实证明,这只是缺少一个简单的语句。

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

连同我在问题中编写的代码。

关于ios - ios 通话后恢复在后台运行的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22006200/

相关文章:

iphone - iOS App无法在后台运行

ios - 在每个 Alamofire 请求之前/之后调用一个函数

ios - 多个 NSPersistentStoreCoordinator 实例可以连接到同一个底层 SQLite 持久存储吗?

css - 如何让自定义 CSS 按钮根据图像自动调整大小

单选按钮的 CSS 背景

iPhone应用程序后台网络通信

perl 多任务问题

ios - 我应该如何构建我的应用程序来处理传入的蓝牙数据?

iphone - 将 subview 添加到自定义类的 super View 不起作用

html - 如何修复 svg 背景的错误?