呼叫激活时是否有可能运行加速度计?
您好,在我的项目中,我需要在激活呼叫时调用加速度计,我使用此代码在通话期间调用加速度计。
- (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 中不可能。或者如果可能的话,那么有什么方法或代码可以实现这一点。
Hi In my project I need to call accelerometer while call is activated I use this code for calling accelerometer during call.
- (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];
}
}
But it neither show the call status nor run the acceleration in background during call, and I used this from the latest multitasking function guide from apple iOS but not show the status of call and accelerometer is not running in the background. Is it possible to sense acceleration during call and play a audio file during call or it is not possible in iOS. Or if it is possible then what is the way or code to make it possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
iOS 不是真正的多任务操作系统,因此目前您无法在应用程序处于后台时运行加速计代码。
iOS is not real multitasking operating system, so currently you cannot run accelerometer code while app is at background.