c# - Xamarin iOS 设备 OpenUri 不打开 Whatsapp uri 方案
问题描述
我在 Iphone 中运行我的 Xamarin Cross 平台并且 Device.OpenUri 不工作,这个函数在 Android 平台上按预期工作,但在 iOS 中,当我点击 whatsapp URI 时,它只会重新加载页面而不打开 Whatsapp应用程序
我尝试在 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 没有正确打开,并且在调试控制台中没有给我任何错误。
解决方案
为了打开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 格式是否正确。
推荐阅读
- elm - 如何将多个模块导入 Elm REPL?
- mysql - 将 NA 值从 r 加载到 sql
- c++ - 将本地化的卫星 dll 嵌入到 exe 应用程序中
- c - PS/2 键盘不会发送按键中断,但会响应命令
- string - 如何在PowerShell中将字符串转换为整数?
- node.js - 如何从 Firestore 中的查询返回结果?
- javascript - 如何将html代码块直接插入pug
- prolog - SWI-PL:在 writeln() / write() 之后的 read(),nl 保留所有先前 write() 的输出
- reactjs - onChange 回调返回错误的 id
- sql - 从带有 IN 子句的 3 个表中选择