Q&A
###前提・実現したいこと
Swiftでtodoアプリを作成しており、ユーザーが指定時刻した時間に通知したいです。
###発生している問題・エラーメッセージ
以下のように現時刻から5秒後の通知はできるのですが、UIDatePickerなどから取得した時間を設定したいです。
fireDateプロパティへNSDate型で時間を代入すればできるようなのですが、String型からNSDate型への変換がうまくいってないようです。
ご教示お願いします。
###ソースコード
let notification = UILocalNotification()
notification.fireDate = NSDate(timeIntervalSinceNow: 5);
notification.timeZone = NSTimeZone.defaultTimeZone()
notification.alertBody = "通知だよ"
notification.alertAction = "OK"
notification.soundName = UILocalNotificationDefaultSoundName
UIApplication.sharedApplication().scheduleLocalNotification(notification);
エラー
let todo = Todo()
let data = todo.date.dataUsingEncoding(NSUTF8StringEncoding)
※TodoクラスのdateプロパティにDatePickerから取得したstring型のデータが格納されています。
let notification = UILocalNotification()
notification.fireDate = data
notification.timeZone = NSTimeZone.defaultTimeZone()
notification.alertBody = "通知だよ"
notification.alertAction = "OK"
notification.soundName = UILocalNotificationDefaultSoundName
UIApplication.sharedApplication().scheduleLocalNotification(notification);
回答1件
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2015/10/16 08:42
2015/10/16 09:05
2015/10/16 09:21