Local Notification sound not playing?

寵の児 提交于 2019-12-07 01:58:38

Might be a comparatively simple solution: can you test if it works in the Simulator? If it works in the Simulator and not in the device I'd suggest making sure the mute switch is not on (spent 4 hours yesterday figuring this out).

Abdul Yasin

Hmm, Interestingly, I changed the order of

notification.SoundName = UILocalNotification.DefaultSoundName;
notification.ApplicationIconBadgeNumber = 1;

to

notification.ApplicationIconBadgeNumber = 1;
notification.SoundName = UILocalNotification.DefaultSoundName;

and it works now. When the app is running in background, the local notification fires and plays the default notification sound.

Irfan

Make sure that you are cleaning the old notifications with

UIApplication* app = [UIApplication sharedApplication];
NSArray*  oldNotifications = [app scheduledLocalNotifications];

// Clear out the old notification before scheduling a new one.

[app cancelAllLocalNotifications];

in case you don't want to cancel all notifications then try changing the order of badge number and sound name.

Hopefully this will resolve your problem.

In my case the Simulator works fine. The iPad will play music, etc. The problem was: Next to the volume controls on the iPad, the Ringer switch was Off. This stopped the Alert sounds from getting through.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!