0

I am looking for a private API example on how to show the red pulsating double-height status bar that is used when recording audio. I would like to enable this status bar from my app without starting recording. I want just the status bar and I want it to be system-wide so if I put my app in background I want to see it still. To start recording would actually be a good workaround, the problem is that I need to trigger the status bar from the app while it is running in the background (for example after a silent push)

I remember being able to modify the global status bar in early iOS but I have lost the code and I hope someone know if this can be done in iOS 8 and can share some hints on which API I should use. I know that Apple have locked a lot of functionality behind entitlements now days, I hope though that this is something they haven't locked up.

Please note that this is not for app store submission but rather an internal app and I am not looking for pros and cons about doing this but rather technical info on how to do it.

EDIT:

Just for completeness, I have tried to start recording in the background and this does not seem to work. The code works perfectly when the app is in foreground but when the app is in background it just [self.recorder record] returns false. Being able to start the recorder from background would be perfect, that would also solve my problem. When I try to start recording in background I get "ERROR! Failed to start recorder" (see below)

[[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
    if (!granted) {
        NSLog(@"Permission not granted");
    }
}];

NSError *error;

NSArray *pathComponents = [NSArray arrayWithObjects:
                           [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
                           @"Audio.m4a",
                           nil];
NSURL *outputFileURL = [NSURL fileURLWithPathComponents:pathComponents];

AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryRecord error:&error];

NSDictionary *recordSetting = @{
                                AVFormatIDKey:[NSNumber numberWithInt: kAudioFormatMPEG4AAC],
                                AVSampleRateKey:[NSNumber numberWithFloat:16000.0],
                                AVNumberOfChannelsKey:[NSNumber numberWithInt: 1]
                                };


// Initiate and prepare the recorder
self.recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:&error];
self.recorder.delegate = self;
BOOL prepared = [self.recorder prepareToRecord];
if (!prepared) {
    NSLog(@"ERROR! Failed to prepare recorder");
}

[[AVAudioSession sharedInstance] setActive:YES error:&error];
BOOL isRecording = [self.recorder record];
if (!isRecording) {
    NSLog(@"ERROR! Failed to start recorder");
}
www.jensolsson.se
  • 3,023
  • 2
  • 35
  • 65
  • "while it is running in the background" and what's the problem with that? Just start recording from background and red status bar will show up. It's possible. – creker Nov 26 '14 at 23:40
  • Are you sure? Maybe I am doing something wrong then. When I try to start recording from the background I see the red status bar blink for a fraction of a second to then disappear. Have you managed to start recording from background? That is very interesting to me – www.jensolsson.se Nov 27 '14 at 07:15
  • I didn't test it specifically but remember it working for me. My app was using a hack to stay active in the background - `audio`, `location`, `voip` background modes plus playing silent audio file. And I was able to start audio recording. May be it stopped working on iOS 8, I only tested it on iOS 7. – creker Nov 27 '14 at 08:14
  • I also play an audio file in background to keep running. I also have audio, voip, location background modes enabled. If you are able to dig that code up it would be highly appreciated :) – www.jensolsson.se Nov 27 '14 at 08:17
  • 1
    Strange. Tested it on iOS 8 - works fine but not for your case. I'm able to record audio from the background but it doesn't show red status bar. It flashes for a sec and disappears even though recording is in progress. Resulting file is valid and contains recorded audio. Initialization is pretty much the same - set session category, activate session. For recording I use audio queue API. – creker Nov 27 '14 at 08:56
  • That is very interesting, it flashes very quickly for me too, only difference is that [self.recorder record] returns NO for me while in background. – www.jensolsson.se Nov 27 '14 at 09:34

0 Answers0