iOS Development information hint push way, one kind is remote server push (APNS) and uilocalnotification Local notification, we know uilocalnotification notification repeated prompt unit is in seconds, minutes, hours, days , week, month and so on. :
So the question is, what should I do to achieve the title?
Ha ha...
Small series first thought is the first to judge the system time for the day of the week, and then set 5 weeks for the notification, but considering the very troublesome, small series I most afraid of trouble? He began to consult his (her) people.
This is a beauty oh ~ Here is not introduced, thanks ~ ~
Speaking of this estimated someone to cut people, said so much, quickly say how to solve it ~ ~ Then say how to achieve it!
Workaround
1. Set up a notification in days
#pragma mark Local Notification
-(void) Setlocalnotification: (uilocalnotification *) mlocalnotification withtime: (NSString *) notificationtime Withtitle: (NSString *) alertbody
{
Set the caption of the notification (action name)
Mlocalnotification.alertaction = @ "This is a notification";
Set the body of the notification
Mlocalnotification.alertbody = Alertbody;
Set the time for the notification
NSDateFormatter *formattr = [[NSDateFormatter alloc] init];
Format time
[Formattr setdateformat:@ "hh:mm"];
Trigger Notification time
NSDate *now = [formattr datefromstring:notificationtime];
Mlocalnotification.firedate = Now;
Set a recurring notification for a daily reminder
Mlocalnotification.repeatinterval = Nscalendarunitday; Kcfcalendarunitminute Nscalendarunitday
Sounds that are played when notifications are triggered
Mlocalnotification.soundname = Uilocalnotificationdefaultsoundname;
When canceling the notification, it is the same notification that the key and ID are the same.
Nsdictionary *dict =[nsdictionary Dictionarywithobjectsandkeys:notificationtime, @ "key", nil];
[Mlocalnotification setuserinfo:dict];
Add Notifications with Application
[[UIApplication sharedapplication] schedulelocalnotification:mlocalnotification];
}
2. In -(void) Application: (UIApplication *) application didreceivelocalnotification: (Uilocalnotification *) Notification method to determine whether the weekend, for the weekend to cancel the notice, then someone will ask, how to cancel the notice? Please see the above code, whether the main to my notification set a userinfo, yes, is to traverse so notice, find key the same notification cancellation, or on the code bar!
-(void) Application: (UIApplication *) application didreceivelocalnotification: (uilocalnotification *) notification
{
Nsdictionary *userinfo = Notification.userinfo;
if ([@ "10:00am" isequaltostring:userinfo[@ "key"]) {
if ([toolset Isweekend]) {
Cancel Notification
[Self cancellocalnotificationwithkeyvalue:value];
Re-open
Uilocalnotification *notification = [[Uilocalnotification alloc] init];
[Self setlocalnotification:notification withtime:value withtitle:@ "It's so annoying ..."];
}
}
/** cancel a notification such as: value = @ "10:00" */
-(void) Cancellocalnotificationwithkeyvalue: (NSString *) value
{
Nsarray *notifications=[[uiapplication sharedapplication] scheduledlocalnotifications];
Nsuinteger acount = Notifications.count;
if (acount>0) {
For (uilocalnotification *myuilocalnotification in notifications) {
Nsdictionary *userinfo = Myuilocalnotification.userinfo;
if ([Value isequaltostring:userinfo[@ "key"]) {
[[UIApplication sharedapplication] cancellocalnotification:myuilocalnotification];
NSLog (@ "Cancel:%@", value);
}
}
}
}
All right, give it a try! If there is a better way, please inform, tks!
"Set local notifications for Monday to Friday reminders, no workaround at weekends"