iphone - 如何在iPhone应用程序中播放闹钟音乐?

标签 iphone objective-c ios uilocalnotification

嗨,我正在使用警报应用程序,并使用警报音乐(例如铃声)设置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!"];

  }

请在收到通知后帮助我发出警报。

谢谢...

最佳答案

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

关于iphone - 如何在iPhone应用程序中播放闹钟音乐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13819423/

相关文章:

ios - SWIFT 中的 audioPlayerDidFinishPlaying 函数

iphone - 双击 UINavigationController 导航栏?

iphone - AVCaptureMovieFileOutput开始录制到输出文件URL : recordingDelegate: is not calling delegate

ios - 登录后如何使用 FBSDKLoginKit 注销?

ios - 通过 contentInset 属性添加边距在 iPad 上居中 UITableView?

android - libgdx 还是 playn?

objective-c - 查询核心数据中多个子实体类型的所有对象

ios - Swift:Parse 中的长查询(OR/AND 条件)

ios - AFNetworking 无法序列化 gzip 响应(响应对象为零)

ios - SQLite 错误 : EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, 子代码 = 0x0) -iOS