Vic*_*orT 11
好的,我已经找到了如何在没有SpringBoard和使用合法手段的情况下显示像In-Call状态栏这样的双高状态栏的方法.这是一个解决方案.当应用程序处于baground模式时,有两种方法可以显示具有应用程序名称的双重状态栏:使用套接字连接到VoIP服务或模拟录音.使用第一种方式,您将看到绿色发光状态栏,如果您喜欢红色,则必须使用第二种方式.好的,我使用第二种方法并执行录音模拟.要实现此目的,只需将以下字符串添加到应用程序的PLIST配置文件:
<key>UIBackgroundModes</key>
<array>
<string>voip</string>
<string>audio</string>
</array>
Run Code Online (Sandbox Code Playgroud)
它将告诉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];
}
Run Code Online (Sandbox Code Playgroud)
将此方法添加到应用程序委托,并从didFinishLaunchingWithOptions调用它.另外,据我所知,您可以将音频会话类别设置为AVAudioSessionCategoryPlayAndRecord并使其处于活动状态.如果将此代码添加到项目中,那么如果您将应用程序置于后台,您将看到包含应用程序名称的双高状态栏.
我认为就是这样.
谢谢.
| 归档时间: |
|
| 查看次数: |
4306 次 |
| 最近记录: |