Last active
December 19, 2015 22:18
Saving MP3 to Documents folder in iOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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