gpt4 book ai didi

ios - SBStatusBarController 实例

转载 作者:可可西里 更新时间:2023-11-01 04:21:45 24 4
gpt4 key购买 nike

有人可以帮助我了解如何获取 SBStatusBarController 实例的小示例吗?我看了很多论坛和源代码,但它对我不起作用:(

谢谢。

最佳答案

好的,我已经找到了如何在没有 SpringBoard 的情况下并使用合法手段来显示双倍高度状态栏的方法,例如 In-Call 状态栏。这是一个解决方案。当应用程序处于后台模式时,有两种方法可以显示带有应用程序名称的双倍高度状态栏:使用套接字连接到 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];

}

将此方法添加到您的应用程序委托(delegate)并从 didFinishLaunchingWithOptions 调用它。另外,据我了解,您可以将 Audio Session 类别设置为 AVAudioSessionCategoryPlayAndRecord 并将其激活。如果您将这段代码添加到您的项目中,那么如果您将您的应用程序置于后台,您将看到一个双倍高度的状态栏,其中包含您的应用程序名称。

我想这就是全部。

谢谢。

关于ios - SBStatusBarController 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7246306/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com