Xamarin forms: Issue with Launching IOS App from Xamarin Forms App (Invalid input URL)
Asked Answered
A

1

1

I am trying to open an ios app from my xamarin forms ios app. I have referred this thread for this feature, but I am getting error: "Invalid input URL" message on the output box.

Interface on Main project

public interface IAppHandler
{
    Task<bool> LaunchApp(string uri);
}

IOS

[assembly: Dependency(typeof(OpenAppImplementation))]
namespace Projectname.iOS.Renderer
{
    public class OpenAppImplementation : IAppHandler
    {
        public Task<bool> LaunchApp(string uri)
        {
            try
            {
                var canOpen = UIApplication.SharedApplication.CanOpenUrl(new NSUrl(uri));
                if (!canOpen)
                    return Task.FromResult(false);
                    return Task.FromResult(UIApplication.SharedApplication.OpenUrl(new NSUrl(uri)));
            }
            catch (Exception ex)
            {
                return Task.FromResult(false);
            }
        }
    }
}

Info.plist: App Bundle Identifier details added here.

enter image description here

In the view

ar appname = "App Bundle Identifier";
var result = await DependencyService.Get<IAppHandler>().LaunchApp(appname);
if (!result)
{
Device.OpenUri(new Uri("Appstore link"));
}

When I am trying to open the app I am getting 2020-09-05 13:41:30.761 ProjectName.iOS[1128:451468] -canOpenURL: failed for URL: "Bundle Identifier" - error: "Invalid input URL" on the output box. What I am missing in this implementation?

Atmospheric answered 5/9, 2020 at 8:35 Comment(4)
I can only assume that you're passing an invalid url. Without knowing the actual value you're trying to use it's really impossible to say.Marcellamarcelle
@Marcellamarcelle I have updated the question with more details, could you please have a look?Atmospheric
the uri you should use is "com.catholicbrain.catholicbrain-connect"Marcellamarcelle
@Marcellamarcelle I am using the exact same URI. Did you find any other issue? The left column of LSApplicationQueriesSchemes is blank in my project. But on the thread I have referred have Item 0, Item 1 keys. In my case I can't add anything on the left column. #43944783Atmospheric
C
1

You set the invalid Url Schemes .

in the second App

in info.plist

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>URL Type 1</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>lucas</string>
        </array>
       <key>LSApplicationQueriesSchemes</key>
       <array>
         <string>lucas</string>
       </array>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
    </dict>
</array>

in the first app

You can open it by invoke the line

var canOpen = UIApplication.SharedApplication.CanOpenUrl(new NSUrl("lucas://"));
if (!canOpen)
            return Task.FromResult(false);
return Task.FromResult(UIApplication.SharedApplication.OpenUrl(new NSUrl("lucas://")));
Costume answered 7/9, 2020 at 9:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.