I want to set an alarm every day, please help me. I am so confused about this from many days. I am using this code
-(void)localNotificationWithData:(NSDate *)firDate timeinterval:(int)interval{ NSCalendar *calender = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDate *pickerDate = firDate; NSLog(@"%@",pickerDate); NSDateComponents *dateComponents = [calender components:( NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSWeekCalendarUnit)fromDate:pickerDate]; int rand = arc4random()%100; NSLog(@"%d",rand); for (int i=0; i<[strMarkList length]; i++) { NSString *getselectedCell=[strMarkList substringWithRange:(NSRange){i,1}]; NSLog(@"%i",[getselectedCell intValue]); if ([getselectedCell intValue]== 0) { [dateComponents setDay:1]; [dateComponents setWeekday:1]; NSDate *itemDate = [calender dateFromComponents:dateComponents]; [self repeatWeekDayInterval:itemDate rand:rand]; }else if ([getselectedCell intValue]== 1) { [dateComponents setDay:2]; [dateComponents setWeekday:2]; NSDate *itemDate = [calender dateFromComponents:dateComponents]; [self repeatWeekDayInterval:itemDate rand:rand]; }else if ([getselectedCell intValue]== 2) { [dateComponents setDay:3]; [dateComponents setWeekday:3]; localNofi.repeatInterval = kCFCalendarUnitWeekday+7; NSDate *itemDate = [calender dateFromComponents:dateComponents]; [self repeatWeekDayInterval:itemDate rand:rand]; }else if ([getselectedCell intValue]== 3) { [dateComponents setDay:4]; [dateComponents setWeekday:4]; NSDate *itemDate = [calender dateFromComponents:dateComponents]; [self repeatWeekDayInterval:itemDate rand:rand]; }else if ([getselectedCell intValue]== 4) { [dateComponents setDay:5]; [dateComponents setWeekday:5]; NSDate *itemDate = [calender dateFromComponents:dateComponents]; [self repeatWeekDayInterval:itemDate rand:rand]; }else if ([getselectedCell intValue]== 5) { [dateComponents setDay:6]; [dateComponents setWeekday:6]; NSDate *itemDate = [calender dateFromComponents:dateComponents]; [self repeatWeekDayInterval:itemDate rand:rand]; }else if ([getselectedCell intValue]== 6) { [dateComponents setDay:7]; [dateComponents setWeekday:7]; NSDate *itemDate = [calender dateFromComponents:dateComponents]; [self repeatWeekDayInterval:itemDate rand:rand]; } }
}
-(void)repeatWeekDayInterval:(NSDate *)itemDate rand:(int)rand{ if (localNofi == nil) return; localNofi.fireDate = itemDate; NSLog(@"%@",itemDate); localNofi.timeZone = [NSTimeZone defaultTimeZone]; localNofi.alertBody = @"Time To Weak Up"; localNofi.alertAction = @"View"; localNofi.soundName = @"alarm-clock-bell.caf"; localNofi.applicationIconBadgeNumber = 1; localNofi.repeatInterval = NSWeekCalendarUnit; identifiLclNoti = rand; NSDictionary *infoDict = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%d",identifiLclNoti] forKey:@"identifyKey"]; localNofi.userInfo = infoDict; NSLog(@"%@",localNofi); [[UIApplication sharedApplication] scheduleLocalNotification:localNofi];
}
please tell me what is wrong, or Iβve been stuck with this problem for many days, I searched google many times, but canβt find a good way, please do something for me please help me ...... thanks
source share