10

There's a lot of questions here asking for displaying a red recording bar while in background. It's totally clear I should use AVAudioSession category AVAudioSessionCategoryPlayAndRecord for that. My question is how can I display a green In-Call bar (or at least red bar) in a foreground app when having an active VOIP call in my app? So I could return to call UI tapping a statusbar area, just like Whatsapp or Skype does.

What I've already tried:

  • voip and audio modes in UIBackgroundModes key in Info.plist + setCategory:AVAudioSessionCategoryPlayAndRecord + setActive as suggested in this SO answer (gives me a red statusbar when going background, but nothing while in foreground)
  • Previous + AVAudioSession + setMode:AVAudioSessionModeVoiceChat - didn't work
  • Set kCFStreamNetworkServiceTypeVoIP flag to socket in pjsip sources and recompiled it - didn't help. Also, deprecated since iOS 8.
  • Created a separate socket, set the voip flag for inputStream/outputStream: [self.inputStream setProperty:NSStreamNetworkServiceTypeVoIP forKey:NSStreamNetworkServiceType] (took the sample code from here)

Using pjsip for calls. What else can I try to increase a statusbar height, moving all the UI down? Are there any standard ways to do that, or I should hack it my own by resizing a root UIWindow and setting another green UIWindow under the statusbar?


Edit: Since no answer is found for a standard way to do that, accepted @roman-ermolov answer. For those who will search for an answer I may suggest several options to do it yourself:

  1. Wrap your root viewcontroller inside container, like in Apple's iAdSuite with Storyboards example. Take a look at my sample project for example. Probably the best way to make that bar.
  2. Hack UINavigationBar height (see this approach) - doesn't work for landscape yet, but may probably be solved
  3. Control your main UIWindow's frame yourself, place another UIWindow under the statusbar with the desired content.
Community
  • 1
  • 1
Sega-Zero
  • 3,034
  • 2
  • 22
  • 46
  • Was my answer helpful or may be you are looking for implementation details? If so, could you please provide additional information about your requirements? – Roman Ermolov Aug 10 '16 at 08:45
  • It was very helpful, thank you. I still hope there is a system way to turn on in-call bar, if any. If noone find this, I'll accept your answer – Sega-Zero Aug 10 '16 at 08:52
  • Please can you provide me an answer to do this in my Android Application? – user_1989 Oct 19 '18 at 06:42
  • I'm not an android developer, but I believe you can achieve the same thing with the same technic - embed all of your UI in a container and reduce it's size when needed – Sega-Zero Oct 20 '18 at 07:45
  • Your sample project is the best solution I've come across so far. I've checked your sample project which works but it has few issues with iPhone X+ devices. Tapping on call bar doesn't work. Would you please update your sample project? – Raymond May 13 '20 at 18:22
  • Hope to get some time to update the code. AFAIR, I've added safeAreaInsets.top to callbar height – Sega-Zero May 13 '20 at 20:52
  • So I made a custom callbar view that shows fine.. but how do we go back to the native callkit screen when the callbar is tapped? – Bruce Oct 19 '20 at 03:39
  • You can't do that in foreground – Sega-Zero Oct 20 '20 at 04:29

2 Answers2

8

I have made an investigation of both apps (WhatsApp & Skype) and learned that they used their own UIView for achieving this functionality.

This is Skype: Skype status bar

This is WhatsApp (Reveal can't get real snapshot, but it transmits basic idea): enter image description here

In both apps it is a UIView which starts on top of the screen and several methods for format output text / handle touch on it.

In iOS 10 Apple introduced CallKit.framework, but it seems that it has not that kind of functionality too, so the only way to do it - do it yourself.

Roman Ermolov
  • 7,898
  • 5
  • 27
  • 35
  • How did you able to see hierarchy of skype and whatsapp app if you are not a developer of them and it not opensosurced? – swift2geek Jul 27 '20 at 13:18
  • Ermolov is this still working in ios 11? I tried to attach to the process and seems IM not able to do so. I guess you are do not have sourcecode of whatsapp or skype to be able run it in xcode, am I right? – swift2geek Jul 27 '20 at 16:28
  • Do you know what's the code to to return to user to the call UI when the top bar is tapped? – Bruce Oct 19 '20 at 06:11
  • 1
    @swift2geek of course I don't have it, I had jailbroken phone at that time. – Roman Ermolov Nov 30 '20 at 17:18
3

Roman Ermolov's answer explained that some apps use their own UIView for this functionality, but does not explain how. The way I see it, you have a few options.

If you want to lay the view on top of (and covering) the current view controller, you could create a UIView with a UILabel or your own UIWindow and add that as a subview of your applications' keyWindow.

To have the view stick on top without covering the contents of the view controller, you could take the same approach as above and manually resize the application window or window's root view controller when you add the call bar subview. Alternatively, you could create a UIViewController base class which contains this call bar subview and an outlet for the view's height constraint. The default value of this constraint should be zero. Then, when a call is placed, change the height constraint to your desired call back height. This constraint approach might work on the application's UIWindow as well, but I'm not too familiar with using constraints on an application's window.

JAL
  • 41,701
  • 23
  • 172
  • 300