On the settings page, I want to include three links to
- My app support site
- YouTube app tutorial
- My primary site (ie: linked to a 'Created by Dale Dietrich' label.)
I've searched this site and the web and my documentation and I've found nothing that is obvious.
NOTE: I don't want to open web pages within my app, I just want to send the link to Safari and that link be open there. I've seen numbers of apps doing the same thing in their Settings page so it must be possible.
And, in case you're not sure if the supplied URL
text
has a scheme:Swift 3.0
This supports devices running older versions of iOS as well
In Swift 1.2, try this:
Heres what I did:
I created an IBAction in the header .h files as follows:
I added a UIButton on the Settings page containing the text that I want to link to.
I connected the button to IBAction in File Owner appropriately.
Then implement the following:
Obj C
Swift
(IBAction in viewController, rather than header file)
Take a look at the
-openURL:
method on UIApplication. It should allow you to pass an NSURL instance to the system, which will determine what app to open it in and launch that application. (Keep in mind you'll probably want to check-canOpenURL:
first, just in case the URL can't be handled by apps currently installed on the system - though this is likely not a problem for plainhttp://
links.)openURL(:) was deprecated in iOS 10.0, instead you should use the following instance method on UIApplication: open(:options:completionHandler:)
Example using Swift
This will open "https://apple.com" in Safari.
https://developer.apple.com/reference/uikit/uiapplication/1648685-open