私はUIDatePickerを使って通知をセットアップしました。私の電話でアプリケーションを実行すると、通知が機能していません。SWIFT3で通知が機能しないのはなぜですか?
問題が何ですか?
マイコード:AppDelegate.swift
で
import UIKit
import UserNotifications
class ViewController: UIViewController {
@IBOutlet weak var datePicker: UIDatePicker!
var timer = Timer()
var time = 10
override func viewDidLoad() {
super.viewDidLoad()
scheduleLocalNotification()
}
func scheduleLocalNotification() {
let notification = UILocalNotification()
let dateTime = datePicker.date
notification.alertAction = "Call"
notification.alertBody = "You have a call right now"
notification.fireDate = dateTime
notification.timeZone = NSTimeZone.default
UIApplication.shared.scheduleLocalNotification(notification)
}
@IBAction func pushNotification(_ sender: AnyObject) {
let AlertView = UIAlertController(title: "Time for your call!", message: "Press go to continue", preferredStyle: UIAlertControllerStyle.alert)
AlertView.addAction(UIAlertAction(title: "Go", style: UIAlertActionStyle.default, handler: nil))
self.present(AlertView, animated: true, completion: nil)
}
}
あなたの 'pushNotification'アクションはどのようなトリガーですか? –
あなたに適したソリューションを見つけましたか? –