Repeat UILocalNotification daily at 5 pm

后端 未结 2 955
野的像风
野的像风 2021-01-15 04:38

How to repeat UILocalNotification daily at 5 pm ? Following is my code to set custom time. But i want to notify the user daily at custom or may be static time. I am using iO

2条回答
  •  有刺的猬
    2021-01-15 05:14

    Use this. It may help you

    NSDateFormatter *dat= [[NSDateFormatter alloc]init];
    [dat setLocale:[NSLocale currentLocale]];
    [dat setTimeZone:[NSTimeZone systemTimeZone]];
    
    //[dat setDateFormat:@"YYYY-MM-dd"];// YYYY-MM-dd hh:mm a
    //NSString *dateM=[dat stringFromDate:datM];
    //[dat setDateFormat:@"YYYY-MM-dd h:mm a"];
    NSDate *reminderDate=[NSDate date];
    reminderDate =[reminderDate dateByAddingTimeInterval:1*24*60*60];
    
    UILocalNotification  *missingDreamNotify=[[UILocalNotification alloc]init];
    missingDreamNotify.fireDate=reminderDate;
    missingDreamNotify.timeZone = [NSTimeZone defaultTimeZone];
    missingDreamNotify.alertBody = @"Reminder is set";
    missingDreamNotify.alertAction = @"Show me";
    missingDreamNotify.soundName = UILocalNotificationDefaultSoundName;
    missingDreamNotify.applicationIconBadgeNumber = 1;
    missingDreamNotify.repeatInterval = NSDayCalendarUnit;
    
    [[UIApplication sharedApplication] scheduleLocalNotification:missingDreamNotify];
    

提交回复
热议问题