5

I have created an application included a ringtone, but how can i add it to ringtones of iphone?

Black Frog
  • 11,595
  • 1
  • 35
  • 66
Ulvi
  • 71
  • 1
  • 2
  • 7

2 Answers2

18

Use iTunes file sharing in your app and copy the ringtone file to the app's documents directory.

  1. Set "Application supports iTunes file sharing" to YES in your info.plist

  2. Wherever appropriate in your app copy out the file with the code below:

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];

The user can now access the ringtone via itunes and add it to their device's ringtones.

swilliams
  • 48,060
  • 27
  • 100
  • 130
Michael Behan
  • 3,433
  • 2
  • 28
  • 38
  • Thank u first of all. I have made a button and a function in my ringtone added project, but i cannot understand what will it do? – Ulvi Apr 04 '11 at 08:51
  • u will see your app in itunes - your devices - Apps. And in Apps under FILE sharing Apps. There you can click on your app and see the file. You can save it to your local pc. Add it under tones and set it as ring tone – veereev Nov 05 '13 at 13:11
0

You cannot. Apple doesn't release an API to export/write ringtones to the operating system.

Black Frog
  • 11,595
  • 1
  • 35
  • 66