4

UILocalNotificationいくつかの特定のオプション (分/時間/日/週/月など) を多かれ少なかれ繰り返すように設定することはできないという投稿をいくつか見ました。

ただし、これらの投稿のいずれも、toのrepeatIntervalプロパティの設定が何を行うかについて言及していません。UILocalNotificationNSWeekdayCalendarUnit

私はこの NSDate と NSCalendar のすべてに非常に慣れていないので、何かが欠けていると確信していますが、ドキュメントを読んだところ、毎週月曜日、火曜日、木曜日に繰り返すNSWeekdayCalendarUnitことができるようです。は 2、3、5 に設定されています。NSLocalNotificationNSWeekdayCalendarUnit

NSWeekdayCalendarUnit 曜日単位を指定します。対応する値は int です。kCFCalendarUnitWeekday に等しい。平日の単位は 1 から N までの数字です (グレゴリオ暦の場合、N=7 で 1 は日曜日です)。

それは正しくありませんか?

前もって感謝します。

4

1 に答える 1

1

はい、できます。私はこのようにします。ユーザーはピッカーでスキームを選択できます。そして、選択は次の方法に進みます。

- (void)setOneLocalAlarmNotification: (NSDate *)firstFireDate withRepeat: (NSInteger)repeat {

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
    return;
localNotif.fireDate = firstFireDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.repeatCalendar = [NSCalendar currentCalendar];

switch(repeat) {
    case 0: 
        break ;
    case 1: 
        localNotif.repeatInterval = kCFCalendarUnitDay;
        break;
    case 2: 
        localNotif.repeatInterval = kCFCalendarUnitWeekday;
        break;
    default: 
        break;
}

// Notification details
localNotif.alertBody = @"Message?";
// Set the action button
localNotif.alertAction = @"Yes";

localNotif.soundName = @"glas.caf"; //UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;

// Specify custom data for the notification
    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"Alarm" forKey:@"type"];
   localNotif.userInfo = infoDict;

// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release]
}
于 2011-03-24T21:24:24.130 に答える