【问题标题】:Xamarin forms: Issue with Launching IOS App from Xamarin Forms App (Invalid input URL)Xamarin 表单:从 Xamarin 表单应用程序启动 IOS 应用程序的问题(输入 URL 无效)
【发布时间】:2020-12-24 08:46:12
【问题描述】:

我正在尝试从我的 xamarin forms ios 应用程序中打开一个 ios 应用程序。我已经为此功能推荐了this 线程,但我在输出框中收到error: "Invalid input URL" 消息。

主项目界面

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 详细信息。

在视图中

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

当我尝试打开应用程序时,我在输出框中收到2020-09-05 13:41:30.761 ProjectName.iOS[1128:451468] -canOpenURL: failed for URL: "Bundle Identifier" - error: "Invalid input URL"。我在这个实现中缺少什么?

【问题讨论】:

  • 我只能假设您传递的网址无效。在不知道您尝试使用的实际价值的情况下,真的不可能说出来。
  • @Jason 我已经更新了问题的更多细节,你能看看吗?
  • 你应该使用的uri是“com.catholicbrain.catholicbrain-connect”
  • @Jason 我使用的是完全相同的 URI。有没有发现其他问题? LSApplicationQueriesSchemes 的左栏在我的项目中是空白的。但是在我提到的线程上有 Item 0, Item 1 键。就我而言,我无法在左栏中添加任何内容。 stackoverflow.com/questions/43944283/…

标签: ios xamarin.forms


【解决方案1】:

您设置了无效的 Url Schemes 。

在第二个应用中

在 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>

在第一个应用中

您可以通过调用该行来打开它

var canOpen = UIApplication.SharedApplication.CanOpenUrl(new NSUrl("lucas://"));
if (!canOpen)
            return Task.FromResult(false);
return Task.FromResult(UIApplication.SharedApplication.OpenUrl(new NSUrl("lucas://")));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-22
    • 2020-05-23
    • 1970-01-01
    • 2017-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多