-1

アラーム用の小さな iOS アプリケーションが必要です。特定の日時を選択すると、通知が発生するはずです。

終日を選択すると、毎日そのアラームが発生するはずです。このアプリケーションで私を助けてください。すでにコードを持っている場合は私に送ってください.

前もって感謝します。

4

2 に答える 2

2

以下のコードを試してください。

UILocalNotification *localNotif = [[UILocalNotification alloc]init];

NSCalendar *calendar = [NSCalendar currentCalendar];
NSDate *datePickerDate = [NSDate date];
NSDateComponents *dateComponents = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit) fromDate:datePickerDate];
NSDateComponents *timeComponents = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:datePickerDate];

NSDateComponents *dateComps = [[NSDateComponents alloc]init];
[dateComps setYear:[dateComponents year]];
[dateComps setMonth:[dateComponents month]];

[dateComps setHour:[timeComponents hour] ];
[dateComps setMinute:[timeComponents minute]];
[dateComps setSecond:00];

NSDate *fireDate = [calendar dateFromComponents:dateComps];
//NSLog(@"%@",fireDate);
localNotif.fireDate = fireDate;
localNotif.soundName = UILocalNotificationDefaultSoundName;
//localNotif.repeatInterval = 1.0;
localNotif.alertAction = @"Alarm";
//NSLog(@"%@",alarmId);

//for alarm once
if ([alarm.repeat_mode_id intValue] == 0) {


} else if([alarm.repeat_mode_id intValue] == 1) { //for alarm every day
    localNotif.repeatInterval = NSDayCalendarUnit;
}
localNotif.alertBody = alarm.alarm_label;
[[UIApplication sharedApplication]scheduleLocalNotification:localNotif];
于 2013-06-11T04:50:27.790 に答える