4

毎日アラームを設定したいのですが、助けてください。何日もの間、とても混乱しています。私はこのコードを使用しています

-(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];

}

何が間違っているか教えてください、または私は何日もこの問題に悩まされています。Googleで何度も検索していますが、良い方法が見つかりません。何かしてください。助けてください......ありがとう

4

1 に答える 1