【问题标题】:Xamarin iOS Device OpenUri dont oppening Whatsapp uri schemeXamarin iOS 设备 OpenUri 不打开 Whatsapp uri 方案
【发布时间】:2019-08-20 01:10:18
【问题描述】:

我在 Iphone 中运行我的 Xamarin Cross 平台,但 Device.OpenUri 无法正常工作,此功能在 Android 平台中按预期工作,但在 iOS 中,当我单击 whatsapp URI 时,它只会重新加载页面而不会打开Whatsapp APP

我尝试在 info.plist 中的 LSApplicationQueriesSchemes 中添加“whatsapp”引用,但未成功

            Hipnosoftpage.IsVisible = false;
            ErroRede = true;

            DisplayAlert("Sem Conexão", "Verifique sua conexão com a internet.", "Tentar Novamente").ContinueWith(t =>
            {
                Hipnosoftpage.Reload();

            }, TaskScheduler.FromCurrentSynchronizationContext());

        }
        var url = e.Url;
        if (url.StartsWith("whatsapp://", StringComparison.InvariantCultureIgnoreCase))
        {
            try
            {
                Device.OpenUri(new Uri(url));
                Hipnosoftpage.GoBack();
            }
            // Can not catch Android exception type in NetStd/PCL library, so hack it...
            catch (Exception ex) when (ex.Message.StartsWith("No Activity found to handle Intent", StringComparison.InvariantCulture))
            {
                // WhatsApp not installed : Android.Content.ActivityNotFoundException: No Activity found to handle Intent
                Console.WriteLine(ex);
            }
        }



    }

我希望 whatsapp 打开,但 Device.OpenUri 没有正确打开,并且在调试控制台中没有给我任何错误。

【问题讨论】:

  • 你能给我们一个 url 可能包含的示例吗?显然它以 whatsapp:// 开头,但后面跟着什么参数
  • 是的,类似于api.whatsapp.com/…
  • 你的网址应该以whatsapp://开头;所以你的意思是“whatsapp://send?1=pt_BR&phone=TELNUMBER&text=MESSAGE”?
  • 你的手机安装Whatsapp了吗?您还必须检查 url 格式。看到这些线程可能会有所帮助:whatsappopen-whatsapp

标签: c# xamarin.forms


【解决方案1】:

要打开whatsapp,您只需要以下内容:

public static void OpenWhatsapp(string phoneNumber, string message = null)
        {
            try
            {
                var uriString = "whatsapp://send?phone=" + phoneNumber;

                if (!string.IsNullOrWhiteSpace(message))
                    uriString += "&text=" + message;

                Device.OpenUri(new Uri(uriString));

            }

检查你的 Uri 格式是否正确。

【讨论】:

  • 我会在星期一检查
  • 我试过了,应用一直打不开whatsapp
【解决方案2】:

使用这个插件解决了:Xamarin.Forms.OpenWhatsApp 感谢 Juliano Custodio, 并以这种方式解析参数。

           `var uri = new Uri(url);
            var query = HttpUtility.ParseQueryString(uri.Query);
            var tel = query.Get("phone");
            var msg = query.Get("text");
            Chat.Open(tel,msg);`

谢谢大家。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-17
    • 1970-01-01
    • 2013-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-08
    相关资源
    最近更新 更多