更新时间:2022-12-08 09:19:42
您设置了无效的网址方案.
在info.plist
中 < key> CFBundleURLTypes</key>< array>< dict>< key> CFBundleURLName</key>< string> URL类型1</string>< key> CFBundleURLSchemes</key>< array>< string> lucas</string></array>< key> LSApplicationQueriesSchemes</key>< array>< string> lucas</string></array>< key> CFBundleTypeRole</key>< string>编辑器</string></dict></array>
您可以通过调用行来打开它
var canOpen = UIApplication.SharedApplication.CanOpenUrl(new NSUrl("lucas://")));如果(!canOpen)返回Task.FromResult(false);返回Task.FromResult(UIApplication.SharedApplication.OpenUrl(new NSUrl("lucas://"))));
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?
You set the invalid Url Schemes .
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>
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://")));