9

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.
4

2 回答 2

8

我对这两个应用程序(WhatsApp 和 Skype)进行了调查,并了解到他们使用自己的 UIView 来实现此功能。

这是Skype: Skype 状态栏

这是 WhatsApp(Reveal 无法获得真实快照,但它传达了基本思想): 在此处输入图像描述

在这两个应用程序中,它都是一个从屏幕顶部开始的 UIView,以及几种用于格式化输出文本/处理触摸的方法。

在 iOS 10 Apple 引入了CallKit.framework,但它似乎也没有那种功能,所以唯一的方法是 - 自己做。

于 2016-08-06T10:46:57.233 回答
3

Roman Ermolov 的回答解释说,一些应用程序使用自己的UIView功能来实现此功能,但没有解释如何。在我看来,你有几个选择。

如果您想将视图放在(并覆盖)当前视图控制器的顶部,您可以UIView使用 aUILabel或您自己的创建一个UIWindow并将其添加为您的应用程序的子视图keyWindow

要让视图贴在顶部而不覆盖视图控制器的内容,您可以采用与上述相同的方法,并在添加调用栏子视图时手动调整应用程序窗口或窗口的根视图控制器的大小。或者,您可以创建一个UIViewController基类,其中包含此调用栏子视图和视图高度约束的出口。此约束的默认值应为零。然后,在拨打电话时,将高度限制更改为您想要的回调高度。这种约束方法也可能适用于应用程序UIWindow,但我不太熟悉在应用程序窗口上使用约束。

于 2016-08-08T22:47:38.903 回答