我正在尝试在运行于 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 中找到一些有趣的东西。
你应该看看这篇文章,我认为它可能对你有帮助。
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/