似乎无法获得一些基本通知。
我使用本地通知将警报声音发送给用户。
我每小时都可以收到通知。
我似乎无法每半小时(每30分钟,或30分钟或1小时)或每15分钟工作一次。
如何为每小时重复间隔设置一个偏移量?通知未触发。
如果无法做到这一点,我将如何手动编写一个执行此操作的循环,直到64个排队通知的限制为止?
UIUserNotificationType types = UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *components = [calendar components:(NSCalendarUnitHour | NSCalendarUnitMinute) fromDate:[NSDate date]];
NSInteger hour = [components hour];
NSDate *h = [calendar dateBySettingHour:hour+1 minute:0 second:0 ofDate:[NSDate date] options:0];
NSDate *f = [calendar dateBySettingHour:hour minute:15 second:0 ofDate:[NSDate date] options:0];
NSDate *ha = [calendar dateBySettingHour:hour minute:30 second:0 ofDate:[NSDate date] options:0];
NSDate *q = [calendar dateBySettingHour:hour minute:45 second:0 ofDate:[NSDate date] options:0];
if (selected == 0)
{
UILocalNotification *notification = [[UILocalNotification alloc] init];
if (notification)
{
notification.repeatInterval = NSCalendarUnitHour;
notification.alertBody = nil;
notification.alertAction = nil;
notification.soundName = @"4.mp3";
notification.fireDate = h;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
}
else if (selected == 1)
{
UILocalNotification *notification = [[UILocalNotification alloc] init];
if (notification)
{
notification.fireDate = ha;
notification.repeatInterval = NSCalendarUnitHour;
notification.alertBody = nil;
notification.alertAction = nil;
notification.soundName = @"2.mp3";
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
notification.soundName = @"4.mp3";
notification.fireDate = h;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
}
else
{
UILocalNotification *notification = [[UILocalNotification alloc] init];
if (notification)
{
notification.fireDate = f;
notification.repeatInterval = NSCalendarUnitHour;
notification.alertBody = nil;
notification.alertAction = nil;
notification.soundName = @"1.mp3";
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
notification.soundName = @"2.mp3";
notification.fireDate = ha;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
notification.soundName = @"3.mp3";
notification.fireDate = q;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
notification.soundName = @"4.mp3";
notification.fireDate = h;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
}
答案 0 :(得分:0)
好吧,我再试一次,但它确实有效,但资产没有正确导入。我刚刚在finder中删除了声音文件,并重新导入了它们,应用程序正在解开通知!