iPhone sdk:打开默认消息铃声列表

时间:2014-10-09 07:10:15

标签: ios iphone

在我的应用程序中,我想为即将进行的消息设置设置默认系统消息音。如何打开默认设备alertTones列表。

我尝试过以下代码,但它没有返回任何声音。

NSFileManager *fileManager = [[NSFileManager alloc] init];
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];
    }
}

请帮助。

1 个答案:

答案 0 :(得分:1)

选中此链接https://github.com/TUNER88/iOSSystemSoundsLibrary。我想你在使用这个参考代码和我在iPhone上测试过的工作。我想你是在iPhone模拟器中测试的。它不在模拟器中工作。因此,在设备中测试其工作正常check the attach image which shows the list of the system sound