LocalNotification - ios 7.1 Simulator上的UILocalNotificationDefaultSoundName不起作用

时间:2014-07-24 14:48:00

标签: ios objective-c xcode ios-simulator uilocalnotification

基于此教程Simple iOS Alarm Clock Tutorial我实现了一个AlarmClock应用程序。 通知发射良好但没有声音。

为了解决这个问题,我尝试过: Fix-1并取消选中/选中我的MacOS声音设置。

如何获得简单的AlarmClock-Sound? (信息:Youtube-Sound作品@Simulator)

代码:

-(void)scheduleLocalNotificationWithDate:(NSDate *)fireDate
{

   [[UIApplication sharedApplication] cancelAllLocalNotifications];

   UILocalNotification *notification = [UILocalNotification new];
   notification.fireDate = fireDate;
   notification.soundName = UILocalNotificationDefaultSoundName;
   notification.alertBody = @"Wake-up... !!!";
   notification.alertAction = @"OK";

   //[notification setApplicationIconBadgeNumber:-1];
   notification.applicationIconBadgeNumber = 1; // increment

   [[UIApplication sharedApplication] scheduleLocalNotification:notification];
}

2 个答案:

答案 0 :(得分:2)

您的代码是正确的。这只是因为模拟器的声音不能很好地工作。例如,也没有键盘点击声。如果您将自定义声音分配给本地通知,则可以使用。

答案 1 :(得分:1)

如果您的模拟器中的默认声音名称未被选中,那么它可能不会像您使用UILocalNotificationDefaultSoundName一样响铃,我在我的应用程序包中添加了一个声音文件并用于在我的代码中将其作为声音名称播放,它曾经每次工作