如何从应用程序添加铃声到iPhone的铃声? [英] How to add a ringtone from an application to ringtones of iphone?
问题描述
我创建了一个包含铃声的应用程序,但是如何将其添加到iphone的铃声中?
I have created an application included a ringtone, but how can i add it to ringtones of iphone?
推荐答案
使用iTunes在您的应用程序中共享文件,并将铃声文件复制到应用程序的文档目录。
Use iTunes file sharing in your app and copy the ringtone file to the app's documents directory.
-
设置应用程序支持iTunes文件共享到您的info.plist中的是
Set "Application supports iTunes file sharing" to YES in your info.plist
在适当的时候,您的应用会使用以下代码复制文件:
Wherever appropriate in your app copy out the file with the code below:
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString * documentsDirectory = [paths objectAtIndex:0];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"MyRingtone" ofType:@"m4r"];
NSData *mainBundleFile = [NSData dataWithContentsOfFile:filePath];
[[NSFileManager defaultManager] createFileAtPath:[documentsDirectory stringByAppendingPathComponent:@"MyRingtone.m4r"]
contents:mainBundleFile
attributes:nil];
用户现在可以通过iTunes访问铃声并将其添加到设备的铃声中。
The user can now access the ringtone via itunes and add it to their device's ringtones.
这篇关于如何从应用程序添加铃声到iPhone的铃声?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!