2

I would like to communicate between two Apps installed on the same phone. In order to do this, I read many official documents to understand that I have to implement a Custom URL Scheme.

Before iOS 9, it seems that we have to add a URLType in Info and define the URL Scheme : " ".

But after the iOS 9, it change the way to communicate between Apps.

The url scheme example is discussed in: Querying URL Schemes with canOpenURL.

My App A code below:

@IBAction func sender(sender: AnyObject) {

    let ourapplication : UIApplication = UIApplication.sharedApplication()
    let ourpath : String = "iOSTest://"
        //.stringByAppendingString(urlEncodedText)
    let oururl : NSURL = NSURL(string: ourpath)!

    ourapplication.canOpenURL(oururl)
} 

At My App B, I add a url name iOSTest in Info.plist

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>iOSTest</string>
</array>

When I install the two App on my iPhone to test, it doesn't work at all.

Here is my error!

Error photo

What's wrong with my App?

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
HungCLo
  • 442
  • 2
  • 6
  • 21

1 Answers1

3

You have it setup incorrectly. The app calling canOpenURL is the app that needs to add the custom scheme to the LSApplicationQueriesSchemes list.

Since App A is calling canOpenURL for iIOSTest, it is App A that needs to add iOSTest to the LSApplicationQueriesSchemes list, not App B.

App B would be the app that needs to register that it responds to iOSTest so that it will be opened when some other app calls openURL with a scheme of iOSTest.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Yes, exactly. Just swap both the `LSApplicationQueriesSchemes` – Rajan Maheshwari Apr 17 '16 at 15:22
  • What are you asking? How to register the custom scheme with App B or what code you have to write in App B? Either way, that is an entirely different question. It is all covered in the docs and in many other questions here. This question should be closed since it has been solved. If you need assistance with the additional question, post another question specific to that issue. – rmaddy Apr 18 '16 at 03:09
  • What problem do you have now? – rmaddy Apr 18 '16 at 03:14
  • When I swap the LSApplicationQueriesSchemes to App A, click the canOpenURL button still doesn't work. But when I change the canOpenURL to openUrl, it works!!!! I don't understand why canOpenURL doesn't work? – HungCLo Apr 18 '16 at 03:37
  • Define "doesn't work". What happens? What message do you get? – rmaddy Apr 18 '16 at 03:38
  • Thanks @rmaddy, I finally figure out canOpenURL and openUrl. – HungCLo Apr 18 '16 at 07:28