【问题标题】:How to run command NSLog(@"Alert display...") immidiately when alert Local Notifications show?显示警报本地通知时如何立即运行命令 NSLog(@"Alert display...")?
【发布时间】:2012-07-25 07:01:52
【问题描述】:

当警报本地通知显示时如何立即运行命令 NSLog(@"Alert display...")?...我正在 iphone 中创建一个闹钟,我想在那个时候播放音乐(警报本地通知显示)!我将使用 AVPlayer 在 iphone 中播放来自 ipod 库的音乐!但我做不到。你能帮助我吗!谢谢!

【问题讨论】:

  • 那么,您是要执行“NSLog”还是要在本地通知触发到您的应用时播放音乐?
  • 其实我想在本地通知触发时播放音乐,它播放音乐和警报通知显示是同时的!
  • 您可以使用 UILocalNotification 的 soundname 属性并提供您的自定义声音

标签: iphone notifications local alert


【解决方案1】:

如果您的应用处于后台并暂停,则在弹出 LocalNotification 时您无法执行您的代码。您可以做的是将您的音乐文件分配给 soundName 属性,但请注意您的声音不得超过 30 秒。代码如下:

UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.soundName = @"yourMusicFile.caf";

当然,如果您的应用没有暂停,您可以使用 AVAudioPlayer 播放音乐...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多