【发布时间】:2017-01-29 01:32:29
【问题描述】:
我正在发出通知并观看有关它的教程,当我输入时:
notification.fireDate = NSDate(timeIntervalSinceNow: 0)
它说
参数标签“(timeIntervalSinceNow:)”不匹配任何可用的 重载
我该如何解决这个问题?这是我的代码:
import UIKit
import UserNotifications
class ViewController: UIViewController {
var timer = Timer()
var time = 10
override func viewDidLoad() {
super.viewDidLoad()
timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: Selector(("Notification")), userInfo: nil, repeats: true)
// Do any additional setup after loading the view, typically from a nib.
}
func notification() {
time -= 1
if time <= 0 {
let notification = UILocalNotification()
notification.alertAction = "Call"
notification.alertBody = "You have a call right now"
notification.fireDate = NSDate(timeIntervalSinceNow: 0)
UIApplication.shared.scheduleLocalNotification(notification)
timer.invalidate()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func pushNotification(_ sender: AnyObject) {
let AlertView = UIAlertController(title: "Time for your call!", message: "Press go to continue", preferredStyle: .alert)
AlertView.addAction(UIAlertAction(title: "Go", style: .default, handler: nil))
self.present(AlertView, animated: true, completion: nil)
}
}
【问题讨论】:
-
但是它说我必须让它
notification.fireDate = NSDate() as Date然后它不起作用 -
@LeoDabus 我按照你说的做时没有收到错误,但我得到了线程 1:信号 SIGABRT
-
@LeoDabus 我应该把那个放在哪里?
-
这绝对有效,但现在我离开应用程序时没有收到通知
标签: ios swift nsdate swift3 nstimeinterval