[英]Sound file not playing on Local notification iOS7
我正在iPod Touch(iOS 7)上运行用于本地通知的应用程序。 通知即将到来,但通知的声音未播放。 我已将声音文件放在文件夹中,还检查了设备上的声音设置。 我尝试了许多声音文件,但没有任何效果。 下面是代码:
- (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];
}
有时由于设备原因可能会发生这种情况。 并尝试清除以前的通知:
UIApplication* app = [UIApplication sharedApplication];
[app cancelAllLocalNotifications];
检查此答案 。 这可以帮助您解决问题。
请首先尝试设置->通知中心->声音是否未关闭,然后检查设置->声音->滑块是否未为零,这意味着如果您的声音为零,则不会发出声音。 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.