Search code examples
iosswiftfacebookuiapplication

Opening another (mine) application from my main application Swift


I have two applications and i want to open them from each other (like facebook opens messenger).

After a little search i found that i have to know the url scheme of my app, but i don't know how can i declare it. In my urlSchemes are only facebook's schemes.

var url  = NSURL(string: "")  
UIApplication.sharedApplication().canOpenURL(url!)

I found that code and as i understand i have to put in the url my urlScheme.

Any help?


Solution

  • Here is a good tutorial on setting up URL Schemes within you app: https://dev.twitter.com/cards/mobile/url-schemes

    Incase this tutorial disappears, heres the info:

    Configure our Xcode project

    Go to Your Target > Info > URL Types

    You need to define your custom URL type. Remember, you want to open the app via birdland://, so that will be your URL scheme. We also need to assign an unique identifier to the scheme. Apple recommends that you use reverse DNS notation to ensure that there are no name collisions on the platform, e.g com.mycompany.ios.

    enter image description here

    That’s it! You’ve configured the app with simple support for the URL scheme birdland://. There is, of course, much more that you can do with Custom URL Schemes. To find out more, check out Apple’s documentation.

    Now, to check that our registered URL scheme works, we’ll head out to Safari. Press the “Home” button in the Simulator (or press command-shift-H) to reach the Home Screen. Open Safari.

    Next, type birdland:// in the address bar of Safari. Just as you can with http:// URLs, you’re asking Safari to open the “birdland” scheme. Press Go.