0

I am running application for local notification on iPod Touch (iOS 7). Notification is coming but sound for the notification is not playing. I have placed sound file in folder and also checked sound settings on device. I tried with many sound files but nothing worked. Below is the code :-

- (IBAction) scheduleAlarm:(id) sender {
    [eventText resignFirstResponder];

    NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];

    // Get the current date
    NSDate *pickerDate = [self.datePicker date];

    // Break the date up into components
    NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit ) 
                                                   fromDate:pickerDate];
    NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ) 
                                                   fromDate:pickerDate];

    // Set up the fire time
    NSDateComponents *dateComps = [[NSDateComponents alloc] init];
    [dateComps setDay:[dateComponents day]];
    [dateComps setMonth:[dateComponents month]];
    [dateComps setYear:[dateComponents year]];
    [dateComps setHour:[timeComponents hour]];
    // Notification will fire in one minute
    [dateComps setMinute:[timeComponents minute]];
    [dateComps setSecond:[timeComponents second]];
    NSDate *itemDate = [calendar dateFromComponents:dateComps];
    [dateComps release];

    UILocalNotification *localNotif = [[UILocalNotification alloc] init];
    if (localNotif == nil)
        return;
    localNotif.fireDate = itemDate;
    localNotif.timeZone = [NSTimeZone defaultTimeZone];

    // Notification details
    localNotif.alertBody = [eventText text];
    // Set the action button
    localNotif.alertAction = @"View";

    localNotif.soundName = @"alarm.wav"; ///UILocalNotificationDefaultSoundName;

    //    notify.soundName = @"../Documents/blabla.caf"

    localNotif.applicationIconBadgeNumber = 1;
    localNotif.alertBody = @"Staff meeting in 30 minutes";

    // Specify custom data for the notification
    //  NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
    // localNotif.userInfo = infoDict;

    // Schedule the notification
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    [localNotif release];

    [self.tableview reloadData];
}
Rashad
  • 11,057
  • 4
  • 45
  • 73

2 Answers2

0

Some times this may occur because of the device. And try to clear the previous notification:

UIApplication* app = [UIApplication sharedApplication];
[app cancelAllLocalNotifications];

Check this answer. This may help you solving the problem.

Community
  • 1
  • 1
Rashad
  • 11,057
  • 4
  • 45
  • 73
0

Please try first whether setting->notificationcenter->sounds is not off.Then check whether in setting->sounds->slider is not on zero.That means if u have sounds on zero that will not allow sound to come up. Hope that helps.

shubham jain
  • 156
  • 1
  • 9