連投になりますが、、、
UILocalNotificationのfiretime設定で困っています。
APPdelegete
//バックグラウンドタスクの処理を実行
dispatch_async(dispatch_get_global_queue(
DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
//バックグラウンドタスクの記述
print("バックグラウンドタスクの内容をここに記述")
//ローカルノーティフィケーションの表示(5)
self.checkTime = NSUserDefaults.standardUserDefaults().doubleForKey("Span")
print ("SAPN")
print (self.checkTime)
let notification = UILocalNotification()
notification.alertBody = "タスク完了"
notification.alertAction = "OK"
notification.soundName = UILocalNotificationDefaultSoundName
notification.fireDate = NSDate(timeInterval: self.checkTime, sinceDate: NSDate())
notification.timeZone = NSTimeZone.defaultTimeZone()
app.presentLocalNotificationNow(notification)
//バックグラウンドタスクの終了を通知
self.finishBackgroundTask()
})
viewController
func timeSet(NStime:Double) -> Int{
let now = NSDate()
let formatter = NSDateFormatter()
formatter.dateFormat = "yyyy/MM/dd HH:mm:ss"
Count = Int(NStime)
//秒数を切り捨て
hour = ((Count / 60) / 60)
time = (Count - (hour * 60 * 60))
spanTime = hour + time
print (time)
print(spanTime)
return spanTime
}
viewController側ではdatePickerでカウントダウンの時間を取得
時間と分を秒数に切り替えています。
それをNSUserDefaultsに値を渡し、Appdelegete側で取得し、
X秒後にアラートが表示される。
という計算だったのですが、すぐに通知されてしまいます。
根本がいけないのでしょうか。