Ios 通知部分出错
我正在处理项目的通知部分,在这里我想要声音通知,它将通知用户活动。我使用的代码如下:Ios 通知部分出错,ios,uilocalnotification,Ios,Uilocalnotification,我正在处理项目的通知部分,在这里我想要声音通知,它将通知用户活动。我使用的代码如下: -(void) scheduleNotificationForDate { UILocalNotification *localNotif = [[UILocalNotification alloc] init]; if (localNotif == nil) return; NSCalendar *calendar = [[NSCalendar all
-(void) scheduleNotificationForDate {
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateParts = [[NSDateComponents alloc] init];
[dateParts setHour:18];
[dateParts setMinute:20];
[dateParts setSecond:00];
NSDate *sDate = [calendar dateFromComponents:dateParts];
NSLog(@"date : %@", sDate);
localNotif.fireDate = sDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.alertAction = NSLocalizedString(@"View Details", nil);
localNotif.alertBody = @"Hello Testing";
localNotif.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
NSLog(@"notification started");
}
在这段代码的帮助下,我在我的设备上收到了书面通知,但当通知发出警报时,我没有听到任何警报声。
请查看代码并尝试查找我的错误。你的帮助将是值得感激的 如果你的应用程序处于活动状态,它将不会发出警报声音,请将其置于后台并进行测试
注意:确保您的系统音量已打开。您可能在设置/通知中心禁用了此应用的通知声音?查看您的控制台
date : 0001-01-01 17:26:32 +0000
在过去的2000年中,您已经计划了通知,因为您没有为年、月和日指定组件。设置为“过去”意味着通知将立即发送
如果您想安排今天18:30的通知,您可以执行以下操作:
// get year, month and day components from current time
NSDateComponents *dateParts = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:[NSDate date]];
[dateParts setHour:18];
[dateParts setMinute:20];
[dateParts setSecond:00];
我正在设备中测试…您的应用程序处于后台状态还是挂起或未运行?