【发布时间】:2013-10-20 06:43:06
【问题描述】:
我在应用程序中使用UILocalNotification。
在应用程序中有两个有条件播放的声音——我已经为它们应用了适当的条件。
但是当我安装应用程序并在iOS 7 设备上运行它时,它会触发本地通知,但应用程序中没有播放声音。
下面给出了设置通知的代码:
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
if (localNotification == nil)
return;
localNotification.fireDate = [pickerView date];
localNotification.timeZone = [NSTimeZone defaultTimeZone];
if (alarm_number == 1) {
localNotification.alertBody = [NSString stringWithFormat:@"First Alarm"];
}
else
{
localNotification.alertBody = [NSString stringWithFormat:@"Second Alarm"];
}
localNotification.alertAction =@"Ok";
NSString *message = [[NSString alloc]initWithString:@""];
if(alarm_number == 1)
{
localNotification.soundName=@"Alarm_1.mp3";
message = @"First Alarm Scheduled";
}
else
{
localNotification.soundName=@"Alarm_2.mp3";
message = @"Second Alarm Scheduled";
}
localNotification.applicationIconBadgeNumber = 1;
// Specify custom data for the notification
NSString *alarmString;
if (alarm_number==1) {
alarmString = [NSString stringWithFormat:@"First Alarm"];
}
else
{
alarmString = [NSString stringWithFormat:@"Second Alarm"];
}
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:alarmString forKey:@"AlarmFor"];
localNotification.userInfo = infoDict;
// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[localNotification release];
我检查的是我的应用程序设置/通知中心应用程序中的声音设置。
请浏览第 1 至第 3 张图片以查看我检查过的内容。
(1) 通知中心
(2) 应用
(3) 此处关闭声音
因此,为了启用此功能,我在应用程序目标的 Capabilities 中检查了 Inter App Audio,如下图所示,它处于关闭状态。
应用间音频的功能
然后我将其更改为开启,如下图所示。
然而,它仍然无法在 iOS 7 设备中播放任何声音。
有人知道它为什么不起作用吗?这将是一个很大的帮助。
谢谢。
【问题讨论】:
-
AFAIK,与跨应用音频无关
-
但是你能告诉我什么是确切的问题。我已经尝试了很多。如果你能帮助我。
-
您是否将设置更改为开启声音?
-
其实这才是真正的问题,我们可以手动设置声音。但是我们希望它在安装应用程序时默认开启。
-
这是基于用户的设置。你不能改变它——只有用户可以。
标签: iphone ios audio ios7 uilocalnotification