You can store the file on your device inside a method like this
- (IBAction) record
{
NSError *error;
NSMutableDictionary *settings = [NSMutableDictionary dictionary];
[settings setValue: [NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[settings setValue: [NSNumber numberWithFloat:8000.0] forKey:AVSampleRateKey];
[settings setValue: [NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];
[settings setValue: [NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[settings setValue: [NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
[settings setValue: [NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
[settings setValue: [NSNumber numberWithInt: AVAudioQualityMax] forKey:AVEncoderAudioQualityKey];
NSArray *searchPaths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath_ = [searchPaths objectAtIndex: 0];
NSString *pathToSave = [documentPath_ stringByAppendingPathComponent:[self dateString]];
NSURL *url = [NSURL fileURLWithPath:pathToSave];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setURL:url forKey:@"Test1"];
[prefs synchronize];
recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
[recorder prepareToRecord];
[recorder record];
}
and use it like this:
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
temporaryRecFile = [prefs URLForKey:@"Test1"];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:temporaryRecFile
error:nil];
Convert audio files to NSData, like this
NSData *audioData = [[NSData alloc] initWithContentsOfFile:filePath];
And upload to firebase like this
NSData *data = ...
FIRStorageUploadTask *uploadTask = [riversRef putData:data metadata:nil
completion:^(FIRStorageMetadata *metadata, NSError *error) {
if (error != nil) {
} else {
}
}];
Download file from firebase
FIRStorageReference *islandRef = [storageRef child:@"images/island.jpg"];
NSURL *localURL = [NSURL URLWithString:@"path/to/image"];
FIRStorageDownloadTask *downloadTask = [islandRef writeToFile:localURL
completion:^(NSURL *URL, NSError *error){
if (error != nil) {
} else {
}
}];
Link on how to create storage on firebase in obj C
:
and added a new dateString method to ViewController.m:
- (NSString *) dateString
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"ddMMMYY_hhmmssa";
return [[formatter stringFromDate:[NSDate date]] stringByAppendingString:@".aif"];
}
Firebase storage