2

I am trying to make a call through the telpromt command to return to my application after it makes a call:

NSString *telno = @"telprompt://121,,,,14";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:telno]];

Is there any way to calculate call duration in all situations from my app?

DareDevil
  • 902
  • 8
  • 21
  • I don't know if it works but you could start a timer in `viewDidDisappear` and evaluate that in `viewDidAppear`. – Sebastian Wramba May 27 '14 at 07:50
  • 2
    You can look at CTCoreTelephony framework provided in iPhone sdk, Since the telprompt is not official Apple may remove at in future version with out notice. So even if they approve your app you may still run into trouble later on. – Agent Chocks. May 27 '14 at 07:54
  • check this https://github.com/acerbetti/ACETelPrompt – TonyMkenu May 28 '14 at 08:31
  • I checked the code you provided. But it calculates duration using applicationWillResignActive and applicationDidBecomeActive. I think, it will not work for all cases. For example if call is failed for any reason. Then user will not navigated to app and then duration calculation will not work. – DareDevil May 30 '14 at 08:48
  • Then I tried using CTCoreTelephony framework. Unfortunately it has some bugs. If you are interested, you may check this(http://stackoverflow.com/questions/21195732/how-to-get-a-call-event-using-ctcallcentersetcalleventhandler-that-occurred-wh/21243465#21243465). – DareDevil May 30 '14 at 08:53

1 Answers1

2

Save a NSDate when your app is receiving the applicationWillResignActive, this will be the start of the call. Then in the applicationDidBecomeActive calculate the difference between the saved NSDate and current date. This will give you an rough estimate of the time the call lasted.

Closer than this you will never be able to come.

rckoenes
  • 69,092
  • 8
  • 134
  • 166
  • Thanks, but I think, it will not work for all cases. For example if call is failed for any reason. Then user will not navigated to app and then duration calculation will not work. – DareDevil May 27 '14 at 08:37
  • Well there is no other option, Since there are **no** APIs available to interact with a phone call on the level you require. This has to do with privacy of the user. Either accept it or built an app in Android where this is all possible. – rckoenes May 27 '14 at 08:45
  • whats about CTCallCenter of CTCoreTelephony framework? – DareDevil May 30 '14 at 11:09
  • What about it? It is for monitoring call, but will not give you all the information needed and it does not work well in the background. – rckoenes May 30 '14 at 11:11
  • Yes, it was some problems in background. But I can monitor when a call is established and terminated. It works well for app in forground. But sometimes it broadcast disconnect event before conneted event (I called to IVR). I failed to calculate duration. Still looking for a proper solution... – DareDevil May 30 '14 at 11:30
  • Until now there is not better solutions. – rckoenes May 30 '14 at 11:36