UILocalNotification 自定义声音未在 iOS7 中播放 [英] UILocalNotification custom sound is not playing in iOS7
问题描述
我在应用程序中使用 UILocalNotification
.
I'm using UILocalNotification
in an application.
在应用程序中有两种有条件播放的声音 - 我为它们应用了适当的条件.
In the application there are two sounds which are played conditionally- I have applied proper conditions for them.
但是当我安装应用程序并在 iOS 7
设备上运行它时,它会触发本地通知,但应用程序中没有播放声音.
But when I install the application and run it on an iOS 7
device, then it fires the local notification but a sound is not playing in the application.
下面给出了设置通知的代码:
Code is given below to set the notification:
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];
我检查的是我的应用的设置/通知中心应用中的声音设置.
What I have checked for is the Sound setting in the Settings/Notification Centre app for my app.
请查看第一到第三张图片,看看我检查了什么.
Please go through 1st to 3rd image to see what I have checked.
(1) 通知中心
(2) 申请
(3) 这里没有声音
因此,为了启用此功能,我在应用程序的目标中的 Capabilities 处检查了应用间音频,并且如下图所示关闭.
So, to enable this I have checked Inter App Audio at Capabilities in Targets of the application and it was Off as shown in the image below.
应用间音频功能
然后我将其更改为开,如下图所示.
Then I have changed it to On and it looks like shown in the image below.
然而,它仍然无法在 iOS 7 设备中播放任何声音.
Yet, it still does not play any sound in iOS 7 devices.
有人知道为什么它不起作用吗?这将是一个很大的帮助.
Does anybody have any idea about why is it not working? It would be a great help.
谢谢.
推荐答案
您是否尝试关闭请勿打扰"模式?我有同样的问题,然后我发现请勿打扰"已开启.关闭后,一切正常.
Did you try to turn off "Do not disturb" mode off? I have the same problem, then I found out "Do not Disturb" is on. After turn off that, it all works the right way.
这篇关于UILocalNotification 自定义声音未在 iOS7 中播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!