【问题标题】:Phone dialer issues in xamarin.plugins.messagingxamarin.plugins.messaging 中的电话拨号器问题
【发布时间】:2020-04-01 19:20:09
【问题描述】:
我是 Xamarin 的新手,我只是想直接从我的 Xamarin 应用程序拨打电话。
我只是想在电话号码中包含井号(#)符号作为字符串,但在执行程序时它不包含该符号。
这是代码,
private void Button_Clicked(object sender, EventArgs e)
{
var phoneDialer = CrossMessaging.Current.PhoneDialer;
if (phoneDialer.CanMakePhoneCall)
phoneDialer.MakePhoneCall("*999#");
}
任何帮助将不胜感激!
【问题讨论】:
标签:
visual-studio
xamarin.forms
【解决方案1】:
看看this thread:
具体来说,如果 URL 包含 * 或 # 字符,电话
应用程序不会尝试拨打相应的电话号码。
Swift 中还有一个答案是 iOS11 now allows us to call number with * or # ,我把它翻译成 C#,你可以试试依赖服务:
在shared Project:
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
DependencyService.Get<IPhoneCallTask>().DoPhoneCall();
}
}
public interface IPhoneCallTask
{
void DoPhoneCall();
}
在iOS Project:
[assembly: Dependency(typeof(phoneCall))]
namespace App591.iOS
{
class phoneCall : IPhoneCallTask
{
public void DoPhoneCall()
{
if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
{
NSString number = new NSString("*111*12345#");
NSString encode = number.CreateStringByAddingPercentEncoding(NSUrlUtilities_NSCharacterSet.UrlHostAllowedCharacterSet);
NSString header = new NSString("tel://");
string tmp = string.Format("{0}{1}", encode, header);
NSString urlTemp = new NSString(tmp);
if (UIApplication.SharedApplication.CanOpenUrl(new Uri(urlTemp)))
{
UIApplication.SharedApplication.OpenUrl(new Uri(urlTemp));
}
}
}
}
}