こんにちは私のプロジェクトでは、呼び出しがアクティブになっている間に加速度計を呼び出す必要があります。このコードを使用して、呼び出し中に加速度計を呼び出します。
- (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];
}
}
しかし、通話中に通話ステータスを表示したり、バックグラウンドで加速を実行したりすることはありません.Apple iOSの最新のマルチタスク機能ガイドからこれを使用しましたが、通話のステータスを表示せず、加速度計はバックグラウンドで実行されていません. 通話中に加速度を感知して通話中に音声ファイルを再生することは可能ですか、それとも iOS では不可能ですか。または、可能であれば、それを可能にする方法またはコードは何ですか。