0

In swift, I have a textView with several phone numbers.

When you select the phone number, an action sheet appears that asks the user if they want to call, or cancel.

If the user decides to make the call, how can I tell that the user made the call?

I can intercept the click by using:

func textView(textView: UITextView, shouldInteractWithURL URL: NSURL, inRange characterRange: NSRange) -> Bool {

    label.text = "\(URL)"


    return true

}

However, this is called the second I touch the link. iOS by default opens a prompt that then asks the user whether or not he/she wants to Call or Cancel

I only want to know if they made a call.

How can i do this?

Also disabling the prompt and calling immediately would also work

YichenBman
  • 5,011
  • 8
  • 46
  • 65
  • See http://stackoverflow.com/questions/2543967/how-to-intercept-click-on-link-in-uitextview - It may help. The Core Telephony framework may help with detecting that a call was made (You will only get a disconnected state at the resumption of your app though) or you can take a timestamp in `willBecomeInactive` and compare it in `didBecomeActive` to determine how long the call was. Neither of these approaches are guaranteed or necessarily reliable though – Paulw11 Jun 22 '15 at 22:32
  • gotcha. That helped a lot. With that delegate method i'm able to get which number was pressed. I'm still not totally positive how I'll tell if the call button was actually pressed – YichenBman Jun 22 '15 at 22:42
  • I updated the question – YichenBman Jun 23 '15 at 16:20
  • As I said, you can't ever really know whether the user made a call. When the prompt is displayed you will get a call to `willResignActive` (and the corresponding NSNotification will be posted) and when your app becomes active again you will get a call to `didResumeActive`. If the phone app launches then you should get a call to `willEnterBackground` - you need to test this, but I suspect if you see the sequence `willResignActive`->`didResumeActive` then no call was made. If you see the sequence `willResignActive`->`willEnterBackground` then a call has been placed – Paulw11 Jun 23 '15 at 23:41
  • I'll post the code when I get time but I'm user coretelephony and I'm able to tell if it was dialed, and even connected. So I move in sequential order. If a = true, then if b= true, then if c= true... Do something – YichenBman Jun 23 '15 at 23:42

0 Answers0