毎日同じ時間に通知を送りたかったので、下記のようなコードを書いたのですが、現在時刻よりも前の時間を指定するとすぐに通知が来てしまいます。
現在時刻よりも前の時間を指定したい時はどうしたらいいでしょうか?
swift
1// 通知設定 2 let notification = UILocalNotification() 3 notification.alertAction = "アプリに戻る" 4 notification.alertBody = message 5 notification.timeZone = NSTimeZone.defaultTimeZone(); 6 7 let now = NSDate() 8 print(now) 9 let calendar = NSCalendar(identifier: NSCalendarIdentifierGregorian) 10 let comps:NSDateComponents = calendar!.components([NSCalendarUnit.Year, .Month, .Day], fromDate: now) 11 comps.calendar = calendar 12 comps.hour = hour 13 comps.minute = minute 14 15 let now2 = comps.date 16 print(now2!) 17 18 notification.fireDate = now2 19 20 notification.soundName = UILocalNotificationDefaultSoundName 21 // アイコンバッジに1を表示 22 notification.applicationIconBadgeNumber++ 23 // あとのためにIdを割り振っておく 24 notification.userInfo = ["notifyId": "ranking_update"] 25 26 return notification

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/12/26 02:02