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

时光总嘲笑我的痴心妄想 提交于 2021-02-05 09:44:53

问题


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.

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?


回答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://")));


来源:https://stackoverflow.com/questions/63751993/xamarin-forms-issue-with-launching-ios-app-from-xamarin-forms-app-invalid-inpu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!