我想将设备的系统铃声设置为来自我的应用的本地通知声音。我得到了设备中存在的系统铃声列表,但由于在应用程序捆绑包中无法访问铃声路径,因此无法进行设置以进行通知。有什么方法可以获取访问权限并将其设置为通知声音
经过大量研究,我可以解决我的问题,我只需要将系统/声音复制到Library / Sounds / notification.caf中,如下所示:
NSFileManager* fileManager = [NSFileManager defaultManager];
NSArray *libraryDir = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *lib = [libraryDir objectAtIndex:0];
NSString *directoryPath = [lib stringByAppendingString:@"/Sounds"];
@try {
[fileManager createDirectoryAtPath:directoryPath withIntermediateDirectories:TRUE attributes:nil error:nil];
NSString *systemSoundPath = fromPath; // eg. /System/Library/Audio/UISounds/Tink.caf
NSString *notificationSoundPath = [directoryPath stringByAppendingString:@"/notification.caf"];
BOOL fileExist = [fileManager fileExistsAtPath: notificationSoundPath];
if(fileExist){
[fileManager removeItemAtPath:notificationSoundPath error:nil];
}
[fileManager copyItemAtPath:systemSoundPath toPath:notificationSoundPath error:nil];
} @catch (NSException *exception) {
NSLog(@"in catch");
} @finally {
NSLog(@"in catch");
}
请检查它是否对其他人有帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句