Make a phone number initiate a phone call when tapped?

Hello,

I have a UILabel (currently) on my view that displays a phone number. I want to make that phone number initiate a call when tapped. I've searched around and found info about making it a "tel:" hyperlink, but that doesn't work for me. The UILabel just shows the code. How exactly do I force this to be a link? Or is there a better way to do it?

Thanks,
Bob

Posts

  • PhilippeLeybaertPhilippeLeybaert Philippe Leybaert BEMember ✭✭
    edited November 2012

    You can add a "tap" gesture recognizer to the label and have it execute a call to OpenUrl() on UIApplication:

     UITapGestureRecognizer tap = new UITapGestureRecognizer(
            () => UIApplication.SharedApplication.OpenUrl(new NSUrl("tel:" + label.Text))
     );
    
     label.AddGestureRecognizer(tap);
    
  • Philippe,
    Thanks. Just tried that and I'm getting no response to the tap. Hmmmm.

  • PhilippeLeybaertPhilippeLeybaert Philippe Leybaert BEMember ✭✭

    I forgot to mention that you should set UserInteractionEnabled to true:

    var tap = new UITapGestureRecognizer(
        tap => UIApplication.SharedApplication.OpenUrl(new NSUrl("tel:" + label.Text))
    );
    
    label.UserInteractionEnabled = true;
    
    label.AddGestureRecognizer(tap);
    
  • Ha! I literally JUST remembered to set that. It's firing the event now. THANK YOU!

Sign In or Register to comment.