繁体   English   中英

快速-如何在特定的日期和时间打开日历应用程序?

[英]swift- how to open up calendar app at specific date and time?

我找不到准确的答案,但是我要做的就是:

  1. 用户单击按钮并以毫秒为单位传递日期
  2. 我的应用程序在该特定日期和时间打开了IOS默认日历应用程序。

我正在使用此代码:

let date = Date(timeIntervalSince1970: TimeInterval(timeInMiliFromBackEnd/1000))
let interval = date.timeIntervalSince1970
let url = NSURL(string: "calshow:\(interval)")!
        UIApplication.shared.openURL(url as URL)

日历应用会打开,但是会在某个随机年份(2066年1月@ 3pm)打开。

谁能为此提供迅速的3代码?

干杯〜

iOS不使用timeIntervalSince1970作为“时代日期”。 您应该改用timeIntervalSinceReferenceDate

//Convert the time from the server into a Date object
let seconds = TimeInterval(timeInMiliFromBackEnd/1000)
let date = Date(timeIntervalSince1970: seconds)

//Convert the Date object into the number of seconds since the iOS "epoch date"
let interval = date.timeIntervalSinceReferenceDate
if let url = URL(string: "calshow:\(interval)") {
  UIApplication.shared.open(url, options: [:], completionHandler: nil)
}

(上面的代码已更新为使用较新的open(_:options:completionHandler:)方法,与现已弃用的openURL(_:)方法相对。)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM