Search Unity

Button to make Phone Call

Discussion in 'iOS and tvOS' started by VictorYew, Jul 11, 2011.

  1. VictorYew

    VictorYew

    Joined:
    May 10, 2011
    Posts:
    12
    Hi all,

    Here I am struggling to incorporate the native IOS CALL function into unity. All I want is just to tab on a button and it make a phone call. I've heard about the plugins but I am not sure on how to build the plugins. Any help is much appreciated. T.Q.

    Best regards,
    Victor Yew
     
  2. synapsemassage

    synapsemassage

    Joined:
    Jul 27, 2009
    Posts:
    334
    just import the plugins (usually a unitypackage) and build. that's how it works mostly.
     
  3. VictorYew

    VictorYew

    Joined:
    May 10, 2011
    Posts:
    12
    Thank you for your reply, synapsemassage.

    I know that's usually the case, but according to this page http://unity3d.com/support/documentation/Manual/Plugins.html it means more than that to me. I've searched all over the internet hoping to find one plugin which incorporates the function i mentioned above but with no luck. Perhaps, someone can actually guide me on how to build a native plugin from xcode.
     
  4. synapsemassage

    synapsemassage

    Joined:
    Jul 27, 2009
    Posts:
    334
    Did you take a look at the free NativeToolkit Plugin in the asset store?
     
  5. VictorYew

    VictorYew

    Joined:
    May 10, 2011
    Posts:
    12
    yeah yeah I just found out just now. It does mentioned something I am looking for. I am about to try out. Thank you for the hints anyway.
     
  6. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    Application.OpenURL( "tel://5555551212" ) should work as well if I am not mistaken.
     
  7. defjr

    defjr

    Joined:
    Apr 27, 2009
    Posts:
    436
    Whoa. I am going to test this out. Who should I have people call... :)
     
  8. VictorYew

    VictorYew

    Joined:
    May 10, 2011
    Posts:
    12
    Wow, that's interesting! If that works, then we don't really need a plugin to call out. cool.
     
  9. Rush-Rage-Games

    Rush-Rage-Games

    Joined:
    Sep 9, 2010
    Posts:
    1,997
  10. VictorYew

    VictorYew

    Joined:
    May 10, 2011
    Posts:
    12
    Btw thank you prime31 for doing a great job there to develop those plugins!
     
  11. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Victor, many thanks! We were put here on earth to make sure all the Unity devs can focus on their games and not on all the other silly stuff!
     
  12. Tom88

    Tom88

    Joined:
    Oct 31, 2011
    Posts:
    6
  13. gamedivision

    gamedivision

    Joined:
    Nov 4, 2012
    Posts:
    47
    could someone please elaborate more, I don't script.i need to make a call via a button but where would i put that piece of code and what else does it need
    thank you
    also if someone could point me in the direction of a plugin that would be cool
     
  14. supershwa

    supershwa

    Joined:
    Feb 10, 2013
    Posts:
    12
    If you don't code, you're gonna have a bad time.
     
    arturmandas and tonymedd01 like this.
  15. supershwa

    supershwa

    Joined:
    Feb 10, 2013
    Posts:
    12
    Works great! Didn't realize the phone worked off a URI scheme. Very handy.
     
  16. smtabatabaie

    smtabatabaie

    Joined:
    May 6, 2013
    Posts:
    45
    Hi , I was trying to do the same thing and make a call from a button in unity . I used Application.OpenURL("tel://myNumber") and it works fine . but what I need to do is to use symbols like # and * in the number string and if I use these symbols the rest of the string after these characters won't be send to tel app . I'll appreciate if someone can help me with this .
    thanks so much
     
  17. smtabatabaie

    smtabatabaie

    Joined:
    May 6, 2013
    Posts:
    45
    Last edited: Sep 23, 2013
  18. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    515
    This is pretty wicked! In the stand alone player on my mac it opens up the Skyp ap, it did not dial my phone number on my mac though??? Not sure why??
    But anyways this opens ideas :)
    Is it possible to make a dial screen in unity with GUI Texture buttons so you could dial a number in Unity and then have that number dial out?
    It seems like it could be done but not sure how that would be coded to work with GUI Texture buttons or a dialler ?
     
  19. PaulzCreative

    PaulzCreative

    Joined:
    Oct 5, 2014
    Posts:
    1
    Could this type of command be used for other situations such as opening the default Map app?
     
    unity_RHlCESSIiX9FiQ likes this.
  20. Kharisgun

    Kharisgun

    Joined:
    Aug 2, 2015
    Posts:
    1
    thanks for @prime31 for your command, perfect job very very thanks :) (y)
     
  21. Deleted User

    Deleted User

    Guest

    Appologies for bringing this thread back from the dead but does anyone know if this still works on iOS? I've tried Application.OpenURL("tel:+16048938347") and Application.OpenURL("tel://+16048938347") neither seem to do anything on iOS but both work on Andorid and WebGL
     
  22. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,049
    Please any body can reply in this, how to make phone call in iOS platform???
    @RealWorld do you have any update in this?
     
  23. toddfiore

    toddfiore

    Joined:
    Dec 16, 2016
    Posts:
    12
    Bumping this question.

    Tested on Unity 5.5 with iOS using Application.OpenURL("tel://1234567"), nothing happens. OpenURL works fine for all cases on Android and opens maps and websites on iOS, but not the phone dialer.

    Anyone have any suggestions?
     
  24. Deleted User

    Deleted User

    Guest

    Yes. I got this working. I have a iOS plugin script which is as follows:
    Code (CSharp):
    1. #import <CoreTelephony/CTTelephonyNetworkInfo.h>
    2. #import <CoreTelephony/CTCarrier.h>
    3.  
    4. char* cStringCopy(const char* string)
    5. {
    6.     if (string == NULL)
    7.         return NULL;
    8.    
    9.     char* res = (char*)malloc(strlen(string) + 1);
    10.     strcpy(res, string);
    11.    
    12.     return res;
    13. }
    14.  
    15. // This takes a char* you get from Unity and converts it to an NSString* to use in your objective c code. You can mix c++ and objective c all in the same file.
    16. static NSString* CreateNSString(const char* string)
    17. {
    18.     if (string != NULL)
    19.         return [NSString stringWithUTF8String:string];
    20.     else
    21.         return [NSString stringWithUTF8String:""];
    22. }
    23.  
    24. extern "C"
    25. {
    26.     bool _canOpenURL(const char* cURL)
    27.     {
    28.         UIApplication *application = [UIApplication sharedApplication];
    29.         NSString *nsURL = CreateNSString(cURL);
    30.         NSURL *URL = [NSURL URLWithString:nsURL];
    31.         BOOL canOpen = [application canOpenURL:URL];
    32.        
    33.         if ( canOpen )
    34.         {
    35.             if ( [nsURL hasPrefix:@"tel:"] )
    36.             {
    37.                 // Check if iOS Device supports phone calls
    38.                 CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init];
    39.                 CTCarrier *carrier = [netInfo subscriberCellularProvider];
    40.                 NSString *mnc = [carrier mobileNetworkCode];
    41.                 if (([mnc length] == 0) || ([mnc isEqualToString:@"65535"]))
    42.                 {
    43.                     return false;
    44.                 }
    45.                 else
    46.                 {
    47.                     return true;
    48.                 }
    49.             }
    50.             else
    51.                 return true;
    52.         }
    53.         return false;
    54.     }
    55. }
    From C# you then need
    Code (CSharp):
    1. #if UNITY_IPHONE && !UNITY_EDITOR
    2.     [DllImport ("__Internal")]
    3.     private static extern bool _canOpenURL(string url);
    4.     public static bool CanOpenURL(string url) {
    5.     Debug.Log(string.Format("_canOpenURL({0})", url));
    6.     return _canOpenURL(url); }
    7. #endif
    8.  
    9. #if UNITY_IPHONE && !UNITY_EDITOR
    10.             if ( url.StartsWith("http") || CanOpenURL(url) )
    11.             {
    12.                 Application.OpenURL(url);
    13.                 return true;
    14.             }
    15.             return false;
    16. #endif
    17.  
    18.  
    The phone number should be in the format:
    +[countrycode][area code][number]
    So a UK number would be
    +448081234567

    This works for me without problems but obviously, it doesn't work on a device which is incapable of making calls - so a phone without a SIM or an iPad will return false from canOpenURL. In that instance, I display a popup box with the phone number on it so the user can dial it however they want
     
    siddharth3322 likes this.
  25. nupur7

    nupur7

    Joined:
    Feb 15, 2017
    Posts:
    9
    This causes the telephone screen to open and show the correct number but it doesn't start the call anymore. One has to press the green phone button manually. Is there a way so that the call gets initiated without manually pressing the button? Many thanks..
     
    executer likes this.
  26. executer

    executer

    Joined:
    Mar 29, 2017
    Posts:
    8
    @nupur7 did u get solution.guys any update on this.
     
  27. richardzzzarnold

    richardzzzarnold

    Joined:
    Aug 2, 2012
    Posts:
    140
    Is there any way you can make a call from within an app, without leaving it and opening the phone app? I am trying to make a Kiosk-app that can make calls, but unfortunately it seems that it always needs to leave the app to make calls.Is there a workaround?
     
    KnightRiderGuy likes this.
  28. KnightRiderGuy

    KnightRiderGuy

    Joined:
    Nov 23, 2014
    Posts:
    515
    Ditto! I've been searching high and low for a similar method for my KITT A.I project where in an emergency situation we could instruct the AI to call emergency services onto the scene.

    Is there such a way to do this from a stand alone build that does not require launching an external application?
     
  29. shrirammvasudevan

    shrirammvasudevan

    Joined:
    Mar 31, 2020
    Posts:
    9
    I know this is late but were you able to figure it out? If so, what did you use? Thanks!
     
  30. iamdamon

    iamdamon

    Joined:
    Aug 4, 2020
    Posts:
    1
    Thanks buddy. It solved my problem. However I am adding some more info to make it clearer and more modular for people.

    For people who want to make it modular to use for any mobile number, Follow the below Code :
    Note : This works for Unity Android Build.

    public string phoneURL;
    public TextMeshProUGUI empVehicleNum;

    public void OpenURL()
    {
    phoneURL = "tel://" + empVehicleNum.text;
    Application.OpenURL(phoneURL);
    }

    Use and define references as you please and follow the code above.

    Works like a charm! :D