0

I am working on an iOS application with screen sharing feature using Broadcast Upload extension. I am able to send video packets using UDP connection for screen share in foreground mode but when app goes to background mode no video packets are being delivered to media server. Although audio packets are getting delivered. I have turned on the Audio Airplay and Voip background modes.

Also frames are being added to the capturer using below code.

RTCCVPixelBuffer *rtcPixelBuffer = [[RTCCVPixelBuffer alloc] 
initWithPixelBuffer:pixelBuffer];
int64_t timeStampNs =
CMTimeGetSeconds(CMSampleBufferGetPresentationTimeStamp(sampleBuffer)) 
* NSEC_PER_SEC;
RTCVideoFrame *videoFrame = [[RTCVideoFrame alloc] 
initWithBuffer:rtcPixelBuffer rotation:RTCVideoRotation_0                                                     
timeStampNs:timeStampNs];

//NSLog(@"videoframe %@",videoFrame.buffer.description);
[_videoSource capturer:_capturer didCaptureVideoFrame:videoFrame];

I can see the above frames being added to capturer even in background mode but not able to see anything on server.

Note - All the code for sending data to server is written in containing app and not in extension .

  • To make a app work in background it is not enough to just enable background mode you to add extra code to let application know that this code should work in background mode – Varun Naharia Jan 11 '19 at 06:51
  • @VarunNaharia what code should i exactly write to let application know that i want to write from socket in background mode ? – utkarsh agarwal Jan 11 '19 at 07:36
  • try googling for "[ios background execution](https://www.google.co.uk/search?q=ios+background+execution)" – Sam Mason Jan 11 '19 at 12:36

1 Answers1

0

Apple's replayKit works only on foreground due to security policy apple doesn't allow in the background. in your case when the application goes background there will not generate any video buffer. you can check by debugging in

override func processSampleBuffer(_ sampleBuffer: CMSampleBuffer, with sampleBufferType: RPSampleBufferType) {

}

Sumit Meena
  • 474
  • 3
  • 11
  • This is not true, there are several applications that can constantly record the iPhone/iPad screen, regardless of the recording application being in fore- or background. You just need to create a broadcast extension (that is also ReplayKit). – iSpain17 Sep 11 '19 at 06:25
  • yeah, now you can do that by using broadcast extension – Sumit Meena Sep 11 '19 at 08:25