1
我发现this question,但有点老。看起来他们推荐的the example app目录访问不再可用。如何获取iOS中可用系统声音的列表?
The Apple documentation似乎没有我所需要的。
我需要的是能够列出内置声音(不提供我自己的声音),并允许我的应用程序的用户选择一个播放。
听起来很简单,呃?
UPDATE:
下面是在示例应用程序的相关代码如下所述:
NSURL *directoryURL = [NSURL URLWithString:@"/System/Library/Audio/UISounds"];
NSArray *keys = [NSArray arrayWithObject:NSURLIsDirectoryKey];
NSDirectoryEnumerator *enumerator = [fileManager
enumeratorAtURL:directoryURL
includingPropertiesForKeys:keys
options:0
errorHandler:^(NSURL *url, NSError *error) {
// Handle the error.
// Return YES if the enumeration should continue after the error.
return YES;
}];
for (NSURL *url in enumerator) {
NSError *error;
NSNumber *isDirectory = nil;
if (! [url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:&error]) {
// handle error
}
else if (! [isDirectory boolValue]) {
[audioFileList addObject:url];
}
}
的问题是,普查员总是空的。我怀疑这可能是安全/沙箱问题。
我还没有尝试过的代码,但这看起来应该给你你想要的:https://github.com/TUNER88/iOSSystemSoundsLibrary – DonMag
谢谢。这是我指出的应用程序。它应该列出库目录中的声音文件,但是当我在iOS 10或更高版本中运行它时,我什么也得不到。 –
是的,经过多一点阅读,代码可能只能在越狱......不知道你可以从系统声音中得到什么,基于苹果公司文档的注释:** **注** **系统提供警报声音和系统提供的用户界面声音效果不适用于您的iOS应用程序。例如,使用kSystemSoundID_UserPreferredAlert常量作为AudioServicesPlayAlertSound函数的参数将不会播放任何内容。' – DonMag