有人可以帮我提供如何获取 SBStatusBarController 实例的小样本吗?我查看了很多论坛和源代码,但它对我不起作用:(
谢谢。
好的,我已经找到了如何在没有 SpringBoard 的情况下使用合法手段显示双高状态栏(如通话中状态栏)的方法。这是一个解决方案。当应用程序处于后台模式时,有两种方法可以显示带有应用程序名称的双高状态栏:使用套接字连接到 VoIP 服务或模拟音频录制。使用第一种方式,您将看到绿色发光状态栏,如果您喜欢红色,则必须使用第二种方式。好的,我使用第二种方法,进行录音模拟。为此,只需将以下字符串添加到应用程序的 PLIST 配置文件中:
<key>UIBackgroundModes</key>
<array>
<string>voip</string>
<string>audio</string>
</array>
它将告诉 iOS 您的应用程序将在后台使用音频和 VoIP。现在编码。我们将模拟从麦克风到 NULL 设备的音频录制:
- (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];
}
将此方法添加到您的应用程序委托并从 didFinishLaunchingWithOptions 调用它。另外,据我了解,您可以将音频会话类别设置为 AVAudioSessionCategoryPlayAndRecord 并使其处于活动状态。如果您将此代码添加到您的项目中,那么如果您将应用程序置于后台,您将看到一个双高状态栏,其中包含您的应用程序名称。
我想仅此而已。
Thanks.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)