我使用UIDatePicker设置通知。当我在手机上运行应用程序时,通知不起作用。为什么我的通知不能在SWIFT3中工作?
有什么问题?
我的代码:
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'动作? –
您是否找到适合您的解决方案? –