Xcode - opening urls in safari browser

I am building an app using Hype/Xcode. I currently have a scene which has 4 buttons in it which I wish to open the external Safari browser and load the respective website pages. Is there a simple way to make a button/link open in the Safari browser in iOS? There is an article by Daniel which points to references about how to do this within cordova/phonegap - but nothing about how to do it from within an Xcode project ( Xcode & Phonegap Tips ).

Here is an example Xcode project that uses a Hype project to do this.

The Hype buttons run a javascript which posts messages to the iOS app.

The iOS app is setup to listen for the posted messages and runs a callback handler when it gets them.

The callback handler checks which message was sent and runs a function relating to it.

In this example I used one message post from Hype.
The Hype JS uses the buttons ids to determine what the message posted (message body) will be. ( Different URLS )

The message body is then converted to a swift URL object by the iOS application and opened in Safari.

I have also added a badly constructed URL in one button just to show that the URLS coming from the JS can crash the app if the are not constructed properly.

There is swift code that looks out for this. And also shows how to control the hype document from the App.

hypeXCodeCall2.zip (382.6 KB)

2 Likes

Thanks so much, Mark. This is awesome! If you were in Sydney I’d buy you dinner!

On my way… :grin: