【发布时间】: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