关于 ios:iphone:-播放带有 UILocalNotification 声音的录音

iphone:-play recorded voice with UILocalNotification sound

我可以使用 avrecorder 录制语音,但它将录制的语音保存在文档目录的路径中,我无法找到一种在 localNotification 声音中使用它的方法,所以请任何人对此问题有所了解

录音代码:-

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
-(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];
    }



}

//本地通知的代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
-(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


您只能将应用程序包中的声音用于本地通知

来源


正如 Martin 所说,您只能使用应用程序包中的声音文件。您提到的应用程序"Record alarm free"也无法将录制的声音作为通知声音播放(我已经测试过)。

您可以做的是在从本地通知打开应用程序后播放声音。

你需要在didReceiveLocalNotificationdidFinishLaunchingWithOptions中实现这个:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
-(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];

  }
}

[NSLocalNotification *obj PlaySound];