我想每天设置闹钟,请帮助我,我很困惑很多天。我正在使用此代码
-(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];
/*... here we get Weekdays throug loop....*/
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];
}
}
/*.....end.....*/
// NOW LOCALNOTIFICATION FIRE
}
-(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];
}
请告诉我出了什么问题,或者我在这个问题上停留了很多天我在谷歌上搜索了很多次但找不到任何好的方法请为我做点什么请帮助我......谢谢