ios - Repeat UILocalNotification on Specific day -


i need set uilocalnotification, need take hour , minute datepicker , need set specific date ( : monday ) , repeat on every monday.

i have 2 question :

first 1 ; possible show "day names" "sunday" on date section of date picker?

second question ; correct codes if want set specific date local notification ?

thank answers , here code below ;

-(ibaction) alarmbutton:(id)sender {  nsdateformatter *dateformatter = [[nsdateformatter alloc]init]; dateformatter.timezone = [nstimezone defaulttimezone]; dateformatter.timestyle = nsdateformattershortstyle; dateformatter.datestyle = nsdateformattershortstyle;  nsstring *datetimestring = [dateformatter stringfromdate: datetimepickerset1.date]; nslog ( @"alarm set :%@" , datetimestring);  [self schedulelocalnotificationwithdate1: datetimepickerset1.date];  }  -(void)schedulelocalnotificationwithdate1:(nsdate *)firedate { uilocalnotification *notification = [[uilocalnotification alloc] init];  notification.firedate = firedate; notification.alertbody = @"alarm set !";  [[uiapplication sharedapplication] schedulelocalnotification:notification]; 

question 1 => can not understand want. (but if want display name of days such sunday, monday,....to saturday use uipickerview.)

question 2 => yes can correct date of specific day , can notification on every specific day set localnotification.repeatinterval = nsweekcalendarunit;

for achieve it, need use following piece of (method's) code. method return correct date of specific selected day, need pass day parameter of method such like,

if selected day sunday pass 1
if selected day monday pass 2
.
.
.
if selected day saturday pass 7

here method code :

-(nsdate *) getdateofspecificday:(nsinteger ) day /// here day 1 or 2.. or 7 {   nsinteger desiredweekday = day   nsrange weekdaterange = [[nscalendar currentcalendar] maximumrangeofunit:nsweekdaycalendarunit];   nsinteger daysinweek = weekdaterange.length - weekdaterange.location + 1;    nsdatecomponents *datecomponents = [[nscalendar currentcalendar] components:nsweekdaycalendarunit fromdate:[nsdate date]];   nsinteger currentweekday = datecomponents.weekday;   nsinteger differencedays = (desiredweekday - currentweekday + daysinweek) % daysinweek;   nsdatecomponents *dayscomponents = [[nsdatecomponents alloc] init];   dayscomponents.day = differencedays;   nsdate *resultdate = [[nscalendar currentcalendar] datebyaddingcomponents:dayscomponents todate:[nsdate date] options:0];   return resultdate; } 

and don't forget set localnotification.repeatinterval = nsweekcalendarunit;


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -