Skip to content

Instantly share code, notes, and snippets.

@null-loop
Last active December 19, 2015 22:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save null-loop/6026253 to your computer and use it in GitHub Desktop.
Save null-loop/6026253 to your computer and use it in GitHub Desktop.
Saving MP3 to Documents folder in iOS
- (IBAction)saveRingtoneButtonClicked:(UIButton *)sender {
m_saveRingtoneButtonLowlighted = false;
m_saveRingtoneButtonHighlighted = true;
[self animateSaveRingtoneButton];
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,true);
NSString* sourceFilePath = [[NSBundle mainBundle] pathForResource:[m_activeClip.mp3 componentsSeparatedByString:@"."][0] ofType:@"mp3"];
NSData* mainBundleFile = [NSData dataWithContentsOfFile:sourceFilePath];
NSString* exportPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:m_activeClip.mp3];
NSLog(sourceFilePath);
NSLog(exportPath);
@try {
[[NSFileManager defaultManager] createFileAtPath:exportPath contents:mainBundleFile attributes:nil];
NSLog(@"Ring tone save OK");
[[[GAI sharedInstance] defaultTracker] sendEventWithCategory:@"Ringtone" withAction:@"Save" withLabel:m_activeClip.clipID withValue:0];
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Clip exported" message:@"We've exported the clip as an MP3 - find it in the 'Documents' folder for this app in iTunes." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
@catch (NSException* ex)
{
NSLog(@"Ring tone save failed");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment