0

I am trying to get user action after displaying alert to call on number (UIButton) click.

Problem : When user clicks on number for multiple times it shows alerts for that many instances.

Expected Result : I want to show alert only once.

Following is the line to display alert on number (UIButton) click :

UIApplication.SharedApplication.OpenUrl(url)

I am thinking to disable button action after single click so user can see only one alert.

Can anyone please tell me how to get cancel and call button action when user interact with alert ?

Dan Beaulieu
  • 19,406
  • 19
  • 101
  • 135
  • Why you want to show the AlertView every time user clicks the button? You can try to trigger the `UIApplication.SharedApplication.OpenUrl(url)`, when the user has tapped in enough numbers. – Ax1le May 29 '18 at 10:31
  • Hey Buddy, How's u doing ? Thanks for ur response. – Tushar Mohod May 29 '18 at 13:53
  • let me share a code with you. callNurseButton.TouchUpInside += (sender, e) => { var url = new NSUrl("tel:4806814449"); if (!UIApplication.SharedApplication.OpenUrl(url)) { var av = new UIAlertView("Not supported", "Scheme 'tel:' is not supported on this device", null, "OK", null); av.Show(); }; }; – Tushar Mohod May 29 '18 at 13:54
  • Can you share more code so that I can understand what you have done and what you want to achieve? – Ax1le May 29 '18 at 15:18
  • Code : callNurseButton.TouchUpInside += (sender, e) => { var url = new NSUrl("tel:4806814449"); if (!UIApplication.SharedApplication.OpenUrl(url)) { var av = new UIAlertView("Not supported", "Scheme 'tel:' is not supported on this device", null, "OK", null); av.Show(); }; }; – Tushar Mohod May 29 '18 at 19:10

1 Answers1

0

UIApplication.SharedApplication.OpenUrl(url) will always show an alert to user for selecting whether he wants to make a call. So every time you call this api, an alert will show up.

If you want to check if the url fits your request you can use UIApplication.SharedApplication.CanOpenUrl(NSUrl url). This function probes whether there is a handler for the provided URL on the system. For example, if you call this function with "tel://4806814449" on an iPhone, this will return true, but will return false on an iPod Touch.

When this method returns true and the phone numbers are what you want, call the OpenUrl(url) to show the user authentication. Otherwise show the warning alert.

Moreover we should use UIAlertController instead of UIAlertView on iOS 8+.

Ax1le
  • 6,563
  • 2
  • 14
  • 61
  • Thanks for this. After displaying an authentication alert to user, can i get action of user i.e. whether he clicks on Cancel or Call. ? – Tushar Mohod May 30 '18 at 10:54
  • No, we can’t. This alert is owned by system. But we can get it through call kit – Ax1le May 30 '18 at 10:56
  • You can refer to my another [post](https://stackoverflow.com/questions/48310090/xamarin-ios-get-status-back-of-a-phone-call/48315072#48315072) for more details. – Ax1le May 30 '18 at 11:22
  • Hi @TusharMohod, did it help you? – Ax1le Jun 01 '18 at 01:42
  • Hey, I am now with different task. So i have not completed this portion yet. Now i am working on speech recognition part in xamarin ios. going good till now. Will ask for help if i face any difficulty. Thank you very much for showing concern !! – Tushar Mohod Jun 04 '18 at 13:44
  • @ Land Lu - MSFT Please send me your linkedin profile link. – Tushar Mohod Jun 04 '18 at 13:48