嗨在我的项目中,我需要在呼叫激活时呼叫加速度计我在呼叫期间使用此代码呼叫加速度计。
- (void)applicationDidEnterBackground:(UIApplication *)application
{
if(isSlamOff == FALSE){
NSLog(@"Slame is off");
if(callState == CTCallStateConnected) {
UIAccelerometer *accelerometer =[UIAccelerometer sharedAccelerometer];
accelerometer.updateInterval = 0.1;
accelerometer.delegate = self;
}
}
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
UIAccelerationValue x, y, z;
x = acceleration.x;
y = acceleration.y;
z = acceleration.z;
NSLog(@"x is %4.2f, y is %4.2f and z is %4.2f",x,y,z);
magnitude = sqrt(acceleration.x * acceleration.x
+ acceleration.y * acceleration.y
+ acceleration.z * acceleration.z);
NSLog(@"%f",magnitude);
if(magnitude > 2.5){
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"slamshort" ofType:@"wav"];
NSURL *newURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:newURL error: nil];
[newPlayer prepareToPlay];
NSLog(@"Music Is Playing");
AudioSessionSetProperty(kAudioSessionOverrideAudioRoute_Speaker, sizeof(newPlayer),&newPlayer);
[newPlayer setVolume: 1.0];
[newPlayer play];
}
}
但它既没有显示呼叫状态也没有在呼叫期间在后台运行加速,我从苹果iOS的最新多任务功能指南中使用了这个,但没有显示呼叫状态,加速度计没有在后台运行。是否可以在通话期间检测加速并在通话期间播放音频文件,或者在iOS中无法进行。或者如果可能的话,那么使它成为可能的方式或代码是什么。
答案 0 :(得分:0)
iOS并不是真正的多任务操作系统,因此目前在应用处于后台时无法运行加速计代码。