UILocalNotification custom sound is not playing in iOS7

Published

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 [email protected]"Ok";

    NSString *message = [[NSString alloc]initWithString:@""];

    if(alarm_number == 1)
    {
        [email protected]"Alarm_1.mp3";
        message = @"First Alarm Scheduled";
    }
    else
    {
        [email protected]"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

(1) Notification Center

(2) Application

enter image description here

(3) Sound is off here

enter image description 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

Capabilities in Inter-app audio

Then I have changed it to On and it looks like shown in the image below.

Capabilities after changed On

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.

Source: Ios7 Questions

Published
Categorised as audio, ios, ios7, iphone, uilocalnotification

Answers

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.


Holden Hirthe IV

Leave a Reply

Your email address will not be published. Required fields are marked *

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq