2

I have 2 apps , one client and one server. I am trying interapp communication between ios apps using URL schemes

( I have refered to this https://developer.apple.com/documentation/uikit/inter-process_communication/allowing_apps_and_websites_to_link_to_your_content/defining_a_custom_url_scheme_for_your_app as guideline )

This is the plist for client end

<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Viewer</string>
            <key>CFBundleURLName</key>
            <string>com.test.serverendapp</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>serverendapp</string>
            </array>
        </dict>
    </array>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>com.test.serverendapp</string>
    </array>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIMainStoryboardFile</key>
    <string>Main</string>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
        <string>armv7</string>
    </array>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
</dict>
</plist>

Code for iOS end

@IBAction func tapToClient(){
        let urlsrting = "com.test.serverEndApp://requestInfo?userID='22'"
        let url = URL(string: urlsrting)!
        if UIApplication.shared.canOpenURL(url){

            if #available(iOS 10.0, *) {
                UIApplication.shared.open(url, options: [:]) { (success) in
                    print(" this is \(success)")
                }

            } else {
                UIApplication.shared.openURL(url)
            }
        }else{

            let alertController = UIAlertController(title: "Error", message:
                "There is no such server app here", preferredStyle: .alert)
            alertController.addAction(UIAlertAction(title: "Dismiss", style: .default))

            self.present(alertController, animated: true, completion: nil)

        }
    }

The server end

plist

<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Viewer</string>
            <key>CFBundleURLName</key>
            <string>com.test.clientendapp</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>clientendapp</string>
            </array>
        </dict>
    </array>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>com.test.clientendapp</string>
    </array>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIMainStoryboardFile</key>
    <string>Main</string>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
        <string>armv7</string>
    </array>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
</dict>
</plist>

code

 @IBAction func tapToServer(){
        let urlsrting = "com.test.clientEndApp://provideInfo?username='Debanjan'"
        let url = URL(string: urlsrting)!
        if UIApplication.shared.canOpenURL(url){
            if #available(iOS 10.0, *) {
                UIApplication.shared.open(url, options: [:]) { (success) in
                    print(" this is \(success)")
                }

            } else {
                UIApplication.shared.openURL(url)
            }
        }else{
            let alertController = UIAlertController(title: "Error", message:
                "There is no such client app here", preferredStyle: .alert)
            alertController.addAction(UIAlertAction(title: "Dismiss", style: .default))

            self.present(alertController, animated: true, completion: nil)

        }
    }
}

All I get from either of them is

-canOpenURL: failed for URL: "com.test.clientEndApp://provideInfo?username='Debanjan'" - error: "This app is not allowed to query for scheme com.test.clientendapp"

-canOpenURL: failed for URL: "com.test.serverEndApp://requestInfo?userID='22'" - error: "This app is not allowed to query for scheme com.test.serverendapp"

I have followed all the steps and yet am being in this rut . Help me out to realise what am I doing wrong

I am running it on iPhone 8 iOS 12.2 simulator, on xcode 12.2

1
  • Run on device, not simulator. Commented Oct 22, 2019 at 10:49

2 Answers 2

5

You are doing it in opposite way if you register:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>com.test.clientEndApp</string>
</array>

You should be calling this scheme

let urlsrting = "com.test.clientEndApp://provideInfo?username='Debanjan'"

An you were missing com.test. from your LSApplicationQueriesSchemes

Sign up to request clarification or add additional context in comments.

6 Comments

I just did that. It still gives me the error. Please check on the updated plists.
what you did? you still call different url than scheme you register there is a deifference between: com.test.clientEndApp and clientEndApp
I changed the url scheme as you mentioned for client and server app. Client App now has the serverendapp scheme, server has clientendapp scheme
Yeah, even if the com.test prefix is added , it still doesn't work. What I understood from your point, client app should point to serverapp's url scheme and vice versa. I did that and ran the project. Cleaned up my simulator as well
It does not look like you have tried it, and error is completely the same and you are 100% sure that schemes ar set everywhere exactly the same?
|
0

So, thanks to @Lu_, for pointing out my mistakes

Points : 1. The client app will have the scheme for the server app and vice versa 2. The LS should have a whole name and no such com.test or what nots

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.