ios - 有没有办法让 VoIP 应用程序中的来电永远响铃?

标签 ios background voip

我正在开发基于 VoIP 的 IOS 应用。

有两种方法可以在来电时播放一些声音来通知用户:

  1. 发送带有声音的UILocalNotification。声音最多持续 30 秒;
  2. setKeepAliveTimeout:handler: 函数中播放本地音乐 Assets 。但是系统只给了我10秒的操作时间。

有什么方法可以像原生电话应用一样永远播放声音吗?

最佳答案

恐怕@Dan2552 是正确的。

这是苹果 states :

Sounds that last longer than 30 seconds are not supported. If you specify a file with a sound that plays over 30 seconds, the default sound is played instead.


编辑:

使用 AVFoundation 中的 AVAudioPlayer 可以播放音频文件超过 30 秒(或永远播放)

@import AVFoundation;  // module -> no need to link the framework
// #import <AVFoundation/AVFoundation.h> // old style

- (void)playAudio
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"mp3"];
    NSError *error = nil;
    AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];
    if (!error) {
        player.numberOfLoops = -1; // infinite loop
        [player play];
    } else {
        NSLog(@"Audio player init error: %@", error.localizedDescription);
    }
}

然后您必须主线程上调用此方法,而不是设置本地通知的 soundName 属性:

[self performSelectorOnMainThread:@selector(playAudio) withObject:nil waitUntilDone:NO];

关于ios - 有没有办法让 VoIP 应用程序中的来电永远响铃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19517460/

相关文章:

Android:实现一个VoIP程序

ios - 调用 NSUserdefaults 中的函数来解析 Watchkit/Today Widget 数据的最佳实践?

iphone - If-Then 语句困惑,NSURL 结果不正确

html - 尽管给出了正确的图像路径,但仍未显示背景图像

android - 我该如何在后台使用此MP3?

web-applications - IP 电话到 Web 应用程序集成

audio - 通过音频的 M2M 数据的开放标准?

ios - Swift 中的 Double to String 错误

ios - 当两次调用相同的方法时,完成处理程序导致 EXC_BAD_ACCESS

ios - 如何在iOS中为LaunchScreen.xib背景设置线性渐变