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.
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) Notification Center
(2) Application
(3) Sound is off here
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.
Capabilities in Inter-app audio
Then I have changed it to On and it looks like shown in the image below.
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.
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…