I am able to record voice using avrecorder but its saving the recorded voice in the path of documents directory and i am unable to find out a way to use it in localNotification sound so any one plz give some light on this issue
code for recording:-
-(IBAction)startRecording
{
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [searchPaths objectAtIndex:0];
NSLog(@"ccc...%@",documentPath);
if(toggle)
{
toggle = NO;
recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];
strRecordedVoice=[NSString stringWithFormat: @"%.0f.%@", [NSDate timeIntervalSinceReferenceDate] * 1000.0, @"caf"];
recordedTmpFile = [NSURL fileURLWithPath:[documentPath stringByAppendingPathComponent:strRecordedVoice]];
NSLog(@"Using Filepath called: %@",recordedTmpFile);
NSLog(@"Using str: %@",strRecordedVoice);
recorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:&error];
[recorder setDelegate:self];
[recorder prepareToRecord];
[recorder record];
progressView.progress = 0.0;
[recorder recordForDuration:(NSTimeInterval) 2];
lblStatusMsg.text = @"Recording...";
progressView.progress = 0.0;
timer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(handleTimer) userInfo:nil repeats:YES];
}
else
{
toggle = YES;
//Stop the recorder.
[recorder stop];
}
}
//code for localnotification
-(void) scheduleLocalNotificationWithDate:(NSDate *)fireDate
{
UILocalNotification *notification =[[UILocalNotification alloc]init];
notification.fireDate=fireDate;
notification.repeatInterval = 0;
notification.alertAction = NSLocalizedString(@"View", @"View");
notification.soundName = UILocalNotificationDefaultSoundName;
NSDictionary *userDict = [NSDictionary dictionaryWithObject:ap.strAlarmTitle
forKey:kRemindMeNotificationDataKey];
notification.userInfo = userDict;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
[notification release];
}
Reference:-you can see it its an alarm application which uses uilocalnotification
itunes.apple.com/us/app/record-alarm-free/id418511936?mt=8
You can only use sounds from your App bundle for local notifications
source
As Martin said, you can only use sound files from the application bundle. Your mentioned app "Record alarm free" also cannot play the recorded sound as notification sound (I've tested).
What you can do is play the sound after the app has been opened from a local notification.
You need to implement this in didReceiveLocalNotification
and didFinishLaunchingWithOptions
:
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
[self playSoundWithNotification:notification];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (notification)
{
[self playSoundWithNotification:notification];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With