gpt4 book ai didi

ios - 如何在 Swift3 中执行 timeIntervalSinceNow?

转载 作者:搜寻专家 更新时间:2023-11-01 06:37:37 27 4
gpt4 key购买 nike

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

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com