1

嗨,我正在使用闹钟应用程序,并设置LocalNotifications闹钟音乐之类的铃声。我完美地播放铃声。但问题是在 AlertView 中单击“确定”按钮后,铃声正在播放。我怎样才能玩立即接收LocalNotification

我正在使用以下代码播放铃声:

-(void)application:(UIApplication *)application 
didReceiveLocalNotification:(UILocalNotification *)notification 

{

      application.applicationIconBadgeNumber = 0;

      NSString *reminderText = [notification.userInfo objectForKey:kRemindMeNotificationDataKey];

      NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Mitwa.mp3", [[NSBundle mainBundle] resourcePath]]];

      NSError *error;
      player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
      player.numberOfLoops = -1;

      if (player == nil)
        NSLog([error description]);
      else
        [player play];

      [viewController showReminder:@"Good Evening Mahesh!"];

  }

请帮我在收到通知后播放警报。

谢谢...

4

3 回答 3

4

你不能这样做,你只能设置soundNameon UILocalNotification

如文档中所述:

对于此属性,指定应用程序主包中声音资源的文件名(包括扩展名)或 UILocalNotificationDefaultSoundName 以请求默认系统声音。当系统显示本地通知的警报或标记应用程序图标时,它会播放此声音。默认值为 nil(无声音)。不支持持续时间超过 30 秒的声音。如果您指定的文件的声音播放时间超过 30 秒,则会播放默认声音。

此外,该文件必须在 App 包中,因此在您构建应用程序时它必须存在。

于 2012-12-11T11:32:49.527 回答
1

使用UILocalNotification我们可以设置警报,UILocalNotification 您可以设置声音,但声音应该只有 30 秒。您不能播放超过 30 秒的本地通知声音。如果您在单击警报后想要歌曲,我们可以在您的应用中播放歌曲。

于 2012-12-11T11:50:01.743 回答
1

首先将.mp3文件包含wav到您的 xcode 项目或资源中,然后在声明警报设置的方法中,使用UILocalNotification.

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.soundName = yourSoundName;
于 2012-12-11T11:57:24.180 回答