2016-07-12 8 views
0

私はUILocalNotificationを設定したいと思います。これは毎週金曜日に1回自動的に繰り返されます。私は現在、以下のコードを使用して1日1回の通知を繰り返していますが、今週はこれを作成する方法がわかりません。 UILocalNotification週に1回繰り返す

これは、あなたが毎週繰り返すように設定する方法をある

let calendar: NSCalendar! = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian) 
       let now: NSDate! = NSDate() 
       let notifDate = calendar.dateBySettingHour(19, minute: 0, second: 0, ofDate: now, options: NSCalendarOptions.MatchFirst)! 

       var notification = UILocalNotification() 
       notification.category = "Reminder" 
       notification.alertTitle = "Alert" 
       notification.alertBody = "Alert body" 
       notification.fireDate = notifDate 
       notification.soundName = UILocalNotificationDefaultSoundName 
       notification.repeatInterval = NSCalendarUnit.Day 
       UIApplication.sharedApplication().scheduleLocalNotification(notification) 
+0

repeatIntervalをNSCalendarUnitに変更します。 WeekOfYear。それは毎週同じ時間に繰り返されます。 – brl214

+0

"NSCalendarUnit.Week"が存在しないようです。タイプ 'NSCalendarUnit'に 'Week'のメンバーがありません –

+0

"NSCalendarUnit.WeekOfYear" – brl214

答えて

1

チェックApple DocsここUILocalNotification

いただきありがとうございます。

notification.repeatInterval = NSCalendarUnit.WeekOfYear; 

PS。このコードでは、金曜日だけでなくnotifが作成された日にnotifを作成します。考慮すべき何か。

let now: NSDate! = NSDate() //whatever today's day is and it could be any day between M-Sun 
let notifDate = calendar.dateBySettingHour(19, minute: 0, second: 0, ofDate: now, options: NSCalendarOptions.MatchFirst)! 
+0

エラーメッセージに関する行を使用すると、次のように変更されます:未解決の識別子 'kCFCalendarUnitWeek'の使用 –

+0

試してみる - NSWeekCalendarUnit –

+0

残念ながら同じエラーメッセージ。 –

関連する問題