开发者

Is There any possibility to run accelerometer while call is activated?

开发者 https://www.devze.com 2023-04-13 03:13 出处:网络
Hi In my project I need to call accelerometer while call is activated I use this code for calling accelerometer during call.

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),&newPlay开发者_开发百科er);
    [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.


iOS is not real multitasking operating system, so currently you cannot run accelerometer code while app is at background.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号