2017-01-05 10 views
0

毎週月曜日にローカル通知を送信しようとしています。毎週月曜日に1ヶ月間リマインダをして投薬をしなければならないシナリオがあるとしましょう。 1ヶ月で合計4件の通知となります。私のコードは以下の通りですが、私は以下のことを理解できません。 1)特定の日に通知を送信する方法 2)最大終了日の通知を制限する方法。月曜日のローカル通知のみ

通知を送信するコードは次のとおりです。

let notification = UILocalNotification() 
        notification.alertBody = "Take Medication"      notification.alertAction = "open" // text that is displayed after "slide to..." on the lock screen - defaults to "slide to view" 
        notification.fireDate = NSDate() 
        notification.userInfo = ["title": "notification app", "UUID": "Some Unique Guid"] 
UIApplication.sharedApplication().scheduleLocalNotification(notification) 

誰でも助けてください。 よろしく、 ニーナ

+1

。 – Paulw11

+0

月曜日に来た日付を修正してから、timeIntervalを毎週に設定します。 notification.repeatInterval = NSWeekCalendarUnit; –

答えて

0

はNSDateComponentsにNSWeekCalendarUnitを追加し、NSWeekCalendarUnitにrepeatIntervalを設定します。例については :

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; 
NSDate *now = [NSDate date]; 
NSDateComponents *componentsForFireDate = [calendar components:(NSYearCalendarUnit | NSWeekCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit| NSSecondCalendarUnit | NSWeekdayCalendarUnit) fromDate: now]; 
[componentsForFireDate setWeekday: 2] ; // Monday 
[componentsForFireDate setHour: 18] ; // 4PM 
[componentsForFireDate setMinute:0] ; 
[componentsForFireDate setSecond:0] ; 

    //... 
    notification.repeatInterval = NSWeekCalendarUnit; 
0

あなたが好きなものを管理することができ、あなたはおそらく、複数の通知、あなたがしたい各特定の日付に1つのスケジュールを設定したいと思うでしょう

var notification = UILocalNotification() 

    notification.fireDate! = fireDate // this should be monday with desired timr 


    notification.repeatInterval = NSWeekCalendarUnit //this will repeat every week 
+0

と、1か月後にこの通知をどのように終了するのですか? – neena

+0

UIApplication.shared.cancelLocalNotification(通知) – Lion

関連する問題