Forum Cross Platform with Xamarin

How to open other app in Xamarin forms (iOS)

Hi, I would like to know what is the configuration that I must take into account in the info.plist file to open any application installed on my iOS device. I currently use dependency injection to do this. In the case of Android it works correctly under the following code:

`public Task Launch(string packageName)
{
try
{
Intent intent = Android.App.Application.Context.PackageManager.GetLaunchIntentForPackage(packageName);

            if (intent != null)
            {
                intent.AddFlags(ActivityFlags.NewTask);
                Forms.Context.StartActivity(intent);
            }
            else
            {
                intent = new Intent(Intent.ActionView);
                intent.AddFlags(ActivityFlags.NewTask);
                intent.SetData(Android.Net.Uri.Parse("market://details?id=" + packageName));
                Forms.Context.StartActivity(intent);
            }

            return Task.FromResult(true);
        }
        catch (Exception)
        {
            return Task.FromResult(false);
        }
    }
}`

But I have difficulty implementing it with iOS there I have the following:

` try
{
var canOpen = UIApplication.SharedApplication.CanOpenUrl(new NSUrl($"{packageName}://"));

            if (!canOpen)
            {
                return Task.FromResult(false);
            }

            return Task.FromResult(UIApplication.SharedApplication.OpenUrl(new NSUrl(packageName)));
        }
        catch (Exception ex)
        {
            return Task.FromResult(false);
       }`

I am not sure if I really have to pass the name of the application or the id of the application registered in apple developer in the packageName parameter

Tagged:
Sign In or Register to comment.