为什么我玩UILocalNotification任何声音? [英] Why doesn't my UILocalNotification play any sound?

查看:213
本文介绍了为什么我玩UILocalNotification任何声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我发疯,我相信我有现在想尽一切可能的办法,但我的手机仍然决定保持沉默。我只是希望它的时候我present一个本地通知播放的任何的声音了。目前,无论是 UILocalNotificationDefaultSoundName ,也没有自定义的声音,我加入到我的应用程序包都在工作。我写了使用一个简单的倒计时应用 presentLocalNotification:当倒计时结束

This is driving me nuts, I believe I have tried every possible approach by now, but my phone still decides to stay silent. I just want it to play any sound for now when I present a local notification. Currently, neither the UILocalNotificationDefaultSoundName nor the custom sounds that I added to my app bundle are working. I wrote a simple countdown app that uses presentLocalNotification: when the count down is finished.

- (void)showLocalNotification
{
   UILocalNotification *alarmNotification = [[UILocalNotification alloc] init];
   alarmNotification.alertBody = [NSString stringWithFormat:@"fired at: %@", [NSDate date]];
   alarmNotification.soundName = UILocalNotificationDefaultSoundName; 
   // alarmNotification.soundName = @"glass.aiff"; // "glass.aiff" is a file in my application bundle
   [[UIApplication sharedApplication] presentLocalNotificationNow:alarmNotification];
}

我也展现出 UIAlertView中将被初始化,并从显示的的AppDelegate 收到通知时:

I also show a UIAlertView that will be initialized and displayed from the AppDelegate when the notification is received:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
   UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"alert"  message:@"Local notification was received" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
   [alertView show];
}

本地通知被接收并显示在警报,通知中心,我还可以看到,该通知已经被解雇,只有声音是不工作...

The local notification is received and the alert is shown, in the notification center I can also see that the notification has been fired, only the sound is not working...

我检查的每个的类似的问题上堆栈溢出,使我的所有声音设置,确信在电话通知的应用程序的Settins被启用,我甚至收到推送通知从其他应用程序的同时我在测试里,声音已播放...

I checked every similar question on stack overflow, enabled all my sound settings, made sure that in the Settins of the phone notifications for the app are enabled, I even received push notifications from other apps while I was testing where the sound has been played...

什么是地狱我失去了我的手机不播放任何声音?我必须要进口一些框架或拨打任何东西时,我火了,或者当它收到通知别的吗?

What the hell am I missing that my phone doesn't play any sound? Do I have to import some framework or call anything else on the notification when I fire it or when it is received?

也许最简单的解决办法是,如果有人张贴播放该默认的声音时,通知psented $ P $(虽然我相信我已经写了最低版本自己所需的code的最低版本 - 不同之处在于它不工作)。

Maybe the easiest solution would be if someone would post a minimal version of the code that is needed to play the default sound when a notification is presented (although I believe I already wrote that minimal version myself - except that it doesn't work).

顺便说一句,我都尝试在真实设备上,并在模拟器应用程序,其中没有工作......

By the way, I tried the app both on a real device and in the simulator, none of which worked...


推荐答案

如果您的应用程序在前台时通报火灾,没有声音自动播放。它仅会自动播放声音,如果你的应用程序是在当时的背景。

If your application is in the foreground when the notification fires, no sound is played automatically. It will only play the sound automatically if your app is in the background at the time.

您的截图看起来像你的应用程序可能会在你尝试过当时的前景十分活跃。

Your screenshot looks like your application might have been active in the foreground at the time you tried it.

根据苹果的推送通知文档:

According to Apple's push notification docs:

如果该应用程序是最重要的可见当系统提供的通知,不会显示任何警报,无图标徽章,并没有播放声音。但是,应用程序:didReceiveLocalNotification:如果应用程序委托实现的叫法。该UILocalNotification实例被传入此方法,并委托可以检查其属性,或从用户信息词典中的任何自定义数据。

If the application is foremost and visible when the system delivers the notification, no alert is shown, no icon is badged, and no sound is played. However, the application:didReceiveLocalNotification: is called if the application delegate implements it. The UILocalNotification instance is passed into this method, and the delegate can check its properties or access any custom data from the userInfo dictionary.

您可以随时播放使用AudioServicesPlaySystemSound()方法自己的声音,如果你想。

You can always play the sound yourself using the AudioServicesPlaySystemSound() method if you want to.

这篇关于为什么我玩UILocalNotification任何声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆