iOS 系统声音未播放

标签 ios xcode system-sounds

我正在尝试在运行于 iOS 10.3.1 的应用程序中实现系统声音的播放 我遇到的问题是,当我在 viewDidLoad 中调试应用程序时,正在播放声音。当应用程序正常运行时,它一直在振动。

AudioServicesPlayAlertSoundWithCompletion(1107, nil);

当我想使用相同的系统声音时,在应用程序的特定位置,应该产生声音的适当位置,它什么都不做,在 Debug模式或正常运行时没有声音也没有振动。

当应用程序运行时,我没有看到任何错误或警告。 编辑* 在我使用它的地方添加了一些代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    AudioServicesPlayAlertSoundWithCompletion(1107, nil);
    //AudioServicesPlayAlertSoundWithCompletion(1100, nil); (same)
}

这始终只会振动,无论是否打开铃声,或者手机是否连接到 Xcode 都没有关系。

我已经导入了这个,如果它有意义的话:

#import <AVFoundation/AVFoundation.h>
#import <CoreLocation/CoreLocation.h>
#import "CoreLocationController.h"
#import <AudioToolbox/AudioServices.h>

有人可以帮忙吗?

最佳答案

您可以在 Framework AVFAudio 的 header 中找到一些有趣的东西。

Categories

Headers

你应该看看这篇文章,我认为它可能对你有帮助。

How to play Alert Sound

1) AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
2) AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

Both of the functions vibrate the iPhone. But, when you use the first function on devices that don’t support vibration, it plays a beep sound. The second function, on the other hand, does nothing on unsupported devices. So if you are going to vibrate the device continuously, as an alert, common sense says, use function 2.

关于iOS 系统声音未播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43881606/

相关文章:

ios - 更新数组内结构中的属性

ios - Swift - 节点被触摸后延迟,直到它可以再次被触摸

ios - 如何在ios中单击按钮时更改按钮的图像

ios - 无法打开文档 “XXXX.xib”。我的 xcode 版本是 4.6.2 及以下。有没有安装 xcode 5 的替代解决方案?

ios - 使用 Travis 进行 Swift CI 测试 - 测试运行器在开始测试执行之前退出

c# - 如何在C#中播放SystemSound并等待其完成?

ios - 使用 Jenkins 和 Xcode 7 通过 TestFlight 构建 iOS 应用程序并分发 .ipa

Xcode 的 "rebase local changes onto upstream changes"?

ios - 尝试在使用 SpeechKit 进行语音识别之前播放系统声音

tortoisesvn - 如何关闭 TortoiseSVN 中的声音?