gpt4 book ai didi

c# - 打电话 ios xamarin

转载 作者:可可西里 更新时间:2023-11-01 05:03:50 29 4
gpt4 key购买 nike

我目前在表格 View 中有一个按钮。我有一个自定义单元格类和一个更新单元格方法。

public void UpdateCell (string subtitle2)
{
call.SetTitle(subtitle2, UIControlState.Normal);
call.TouchUpInside += (object sender, EventArgs e) => {
UIApplication.SharedApplication.OpenUrl(new NSUrl("tel:" + subtitle2));
};
}

但是,当我运行这段代码时,出现错误。

Could not initialize an instance of the type 'MonoTouch.Foundation.NSUrl': the native 'initWithString:' method returned nil. It is possible to ignore this condition by setting MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure to false.

最佳答案

试试这个:

public void UpdateCell (string subtitle2)
{
//Makes a new NSUrl
var callURL = new NSUrl("tel:" + subtitle2);

call.SetTitle(subtitle2, UIControlState.Normal);
call.TouchUpInside += (object sender, EventArgs e) => {
if (UIApplication.SharedApplication.CanOpenUrl (callURL)) {
//After checking if phone can open NSUrl, it either opens the URL or outputs to the console.

UIApplication.SharedApplication.OpenUrl(callURL);
} else {
//OUTPUT to console

Console.WriteLine("Can't make call");
}
};
}

不确定是否可以在 iPhone 模拟器中模拟电话调用,否则只需连接您的设备:-)

关于c# - 打电话 ios xamarin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25082089/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com