Swift 如何在 NSTimer 上自动打开 URL

How to Automatically OpenURL on NSTimer in Swift

我正在使用以下代码在 Swift

中打开带有 UIButton 的 URL
UIApplication.sharedApplication().openURL(url!)

这本身就很好用,但我正在寻找用 NSTimer 来做到这一点的方法,目标是 URL 打开时没有任何 "buttons pressed" 由用户.

谁能提供帮助?

用 swift 语言尝试这样

NSTimer.scheduledTimerWithTimeInterval(2.0, target: self, selector: "timerFunctionRun", userInfo: nil, repeats: false)

和功能像这样

func timerFunctionRun () {
  UIApplication.sharedApplication().openURL(url!)
}

它工作正常...

在Swift中使用:

dispatch_after(2.0, dispatch_get_main_queue(), {
    // call your button action here
})

在你的情况下你真的不需要计时器,除非你要重复打开这个 URL。