-2

I'm using the following code to open a URL with a UIButton in Swift

UIApplication.sharedApplication().openURL(url!)

This works very well on its own, but I'm looking for away to do this with an NSTimer with the goal being that the URL opens without any "buttons pressed" by the user.

Can anyone provide assistance?

titan
  • 524
  • 1
  • 6
  • 19
user5208470
  • 91
  • 1
  • 8

2 Answers2

3

Try like this in swift language

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

and function Like ths

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

its work fine ...

Jogendra.Com
  • 6,394
  • 2
  • 28
  • 35
1

In Swift use:

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

You don't really need a timer in your case unless you're repeating the opening of this URL.

Beau Nouvelle
  • 6,962
  • 3
  • 39
  • 54