5

Could somebody help me with small sample how to get SBStatusBarController instance? I took a look at many forums and source codes and it doesn't work for me :(

Thank you.

VictorT
  • 783
  • 10
  • 20
  • I could see that many developers use objc_getClass function to get it and hide from Apple while upload it on AppStore. I tried it and can't get instance. – VictorT Aug 30 '11 at 16:21
  • Hmm.... there is not information about it in inteernet at all. :( – VictorT Aug 31 '11 at 08:45

1 Answers1

13

Ok, I've found the way how to show double-height status bar like In-Call status bar without SpringBoard and using legal means. Here is a solution. There are two ways to show a double-height status bar with application name while an application is in background mode: Connect to VoIP service using sockets or to simulate audio recording. Using the first way you will see a green glowing status bar and if you prefer red color you have to use the second one. Ok, I use the second approach and perform audio recording simulation. To reach this, just add the following strings to PLIST config file of application:

<key>UIBackgroundModes</key>
<array>
    <string>voip</string>
    <string>audio</string>
</array>

It will tells iOS that your application will use audio and VoIP in background. And now code. We will simulate audio recording from microphone to NULL device:

- (void) startRecording
{

    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    NSError *err = nil;
    [audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
    if(err){
        NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
        return;
    }
    [audioSession setActive:YES error:&err];
    err = nil;
    if(err){
        NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
        return;
    }


    recordSetting = [[NSMutableDictionary alloc] init];

    [recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
    [recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
    [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];

    [recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
    [recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
    [recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];


    NSURL *url = [NSURL fileURLWithPath:@"/dev/null"];    
    err = nil;
    recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&err];
    if(!recorder){
        NSLog(@"recorder: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
        UIAlertView *alert =
        [[UIAlertView alloc] initWithTitle: @"Warning"
                                   message: [err localizedDescription]
                                  delegate: nil
                         cancelButtonTitle:@"OK"
                         otherButtonTitles:nil];
        [alert show];
        [alert release];
        return;
    }

    //prepare to record
    [recorder setDelegate:self];
    [recorder prepareToRecord];
    recorder.meteringEnabled = YES;

    BOOL audioHWAvailable = audioSession.inputIsAvailable;
    if (! audioHWAvailable) {
        UIAlertView *cantRecordAlert =
        [[UIAlertView alloc] initWithTitle: @"Warning"
                                   message: @"Audio input hardware not available"
                                  delegate: nil
                         cancelButtonTitle:@"OK"
                         otherButtonTitles:nil];
        [cantRecordAlert show];
        [cantRecordAlert release]; 
        return;
    }

    // start recording
    [recorder record];//recordForDuration:(NSTimeInterval) 40];

}

Add this method to your application delegate and call it from didFinishLaunchingWithOptions. Also, as I understood, you can just set the audio session category as AVAudioSessionCategoryPlayAndRecord and make it active. If you add this code to your project then in case you put your application into the background you will see a double-height status bar with your application name inside.

I think that's all.

Thanks.

Piotr Niewinski
  • 1,298
  • 2
  • 15
  • 27
VictorT
  • 783
  • 10
  • 20
  • You should edit this answer to include the actual answer and then click the gray check mark next to the answer to mark question as answered. – Filip Radelic Sep 02 '11 at 12:08
  • Is there anyway to change the text? E.g. to say "Recording 00:01"? Also, is there anyway to ensure the double-high status bar remains visible while your app is visible? – Teevus Nov 12 '12 at 05:19
  • 1
    @VictorT can you please explain the first method for Green incall status bar ??? Also can we change text as Teevus said – Sneha Bansal Dec 24 '13 at 12:12
  • Hi @VictorT For me `audio` is working fine and for bluetooth application runs fine in background mode also but `redstatusbar` is not displaying like it display in backgroundmode of audio – Chitra Khatri Jul 10 '14 at 04:57
  • If the record settings here does not work, please refer this solution for working record settings. http://stackoverflow.com/a/19438788/620665 – Paramasivan Samuttiram Dec 03 '14 at 10:01
  • but, for me, statusbar showing fraction of second and its disappearing – Anilkumar iOS - ReactNative Jun 23 '15 at 12:38
  • i fixed my issue by adding following code. // Setup audio recording NSDictionary *recordSettings = @{AVFormatIDKey: @(kAudioFormatMPEG4AAC), AVEncoderAudioQualityKey: @(AVAudioQualityLow), AVNumberOfChannelsKey: @1, AVSampleRateKey: @22050.0f}; // and i removed the nsmutabledictionary settings – Anilkumar iOS - ReactNative Jun 24 '15 at 05:03
  • @VictorT can you please explain the first method for Green incall status bar ??? Also can we change text as Teevus said – Please help me – Deepesh Jul 08 '15 at 14:03
  • @Anilkumar I have the same problem, but your solution does not work for me, iPhone 6s – lu yuan Feb 17 '16 at 13:21
  • @luyuan, i was tested with iOS 8, not with iOS9. Sorry! – Anilkumar iOS - ReactNative Feb 17 '16 at 13:46
  • how to show, call duration if app is in background along with red color status bar? – Anilkumar iOS - ReactNative Mar 21 '16 at 09:52
  • @VictorT couldn't show green in-call statusbar while app is foreground, could you post some sample project that shows a green bar? – Sega-Zero Aug 01 '16 at 21:53