![](/img/trans.png)
[英]IOS Swift- App does not open specific selected tab bar controller index when push notification is received
[英]swift- how to open up calendar app at specific date and time?
我找不到准确的答案,但是我要做的就是:
我正在使用此代码:
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.