代碼註冊得到通知是:如何重複本地通知後的iOS 814天和9
UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
和代碼調度通知:
UILocalNotification *notification = [[UILocalNotification alloc] init];
[self setNotificationTypesAllowed];
if (notification)
{
if (allowNotif)
{
notification.timeZone = [NSTimeZone defaultTimeZone];
if ([statusString isEqualToString:@"daily"]) {
notification.fireDate = _timePick.date;
notification.repeatInterval = NSCalendarUnitDay;
}else if ([statusString isEqualToString:@"weekly"]) {
notification.fireDate = _timePick.date;
notification.repeatInterval = NSCalendarUnitWeekOfYear;
}else if ([statusString isEqualToString:@"fortnightly"]) {
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:60*60*24*14];;
notification.repeatInterval = NSCalendarUnitMinute;
//notification.repeatInterval = NSCalendarUnitYear;
}else{
notification.repeatInterval = 0;
}
}
if (allowsAlert)
{
notification.alertBody = [NSString stringWithFormat:@"Do you really want to send message to %@",name];
}
if (allowsBadge)
{
notification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
}
if (allowsSound)
{
notification.soundName = UILocalNotificationDefaultSoundName;
}
notification.alertAction = @"Yes";
notification.timeZone = [NSTimeZone defaultTimeZone];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showSMS) name:@"showSMS" object:nil];
// this will schedule the notification to fire at the fire date
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
我能每週重複本地通知&每週但不重複每兩週,請幫助
嗨Ekta 感謝它的工作 –
上述代碼將不會每14天后重複通知,如果用戶30天未打開應用程序。 –
@RamaniAshish甚至不是第一次? –