ios - 如何在 Swift3 中执行 timeIntervalSinceNow?

标签 ios swift nsdate swift3 nstimeinterval

我正在发出通知并观看有关它的教程,当我输入时:

notification.fireDate = NSDate(timeIntervalSinceNow: 0)

它说

Argument labels '(timeIntervalSinceNow:)' do not match any available overloads

我该如何解决这个问题?这是我的代码:

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)
    }
}

最佳答案

swift 3

let minute:TimeInterval = 11.0 * 60.0;
Date(timeIntervalSinceNow: minute);

到现在 +11 分钟。

关于ios - 如何在 Swift3 中执行 timeIntervalSinceNow?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39605714/

相关文章:

ios - 按钮不起作用(Swift)

ios - 当我在子类中初始化我的 UIView 时会发生什么?

ios - 在 Tab Bar 前面制作 UIPickerView

ios - PDF小猫类似物

javascript - Chromecast 接收器应用程序 - 意外命令,播放器处于 IDLE 状态

ios - Swift 图表 X 轴不显示?

ios - 将 UITableView 添加到 iOS 8 自定义键盘

iPhone/Objective-C - 帮助解决海外时区的 NSDateComponents 和 NSCalendar 问题

iphone - 在枚举期间中断 for 循环( Objective-C )

objective-c - 为什么我需要保留 NSDateFormatter dateFromString : 的结果