c# - 打电话 ios xamarin

标签 c# ios uitableview xamarin.ios xamarin

我目前在表格 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/

相关文章:

c# - 链接按钮动态显示 GridView asp.net

c# - 控制不同的DataContext

ios - 删除UIView动画加速

ios - 使用搜索字符串解析本地 JSON 文件

ios - 在 Swift 中将自定义 UITableViewCell 共享到多个 UITableViewController

ios - Swift 中的 "do-catch"语句执行四次?

c# - 按 Enter 键时出错,C# 控制台

c# - XmlAttributeCollection 无法从 xml 获取属性

ios - 即使我设置了 TableView.separatorStyle = .none,UITableViewCell 之间的细线间隙也是可见的

ios - SDWebImage 的缓存在哪里?