0

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.

JOM
  • 8,139
  • 6
  • 78
  • 111
Jprat
  • 39
  • 8
  • IMHO neither user nor Apple review team like the idea of playing a audio file during the call. – Saran Oct 14 '11 at 06:36

1 Answers1

0

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

JOM
  • 8,139
  • 6
  • 78
  • 111
  • Ya but it is possible when call is activated and app is being in background so when acceleration higher then it predefined value then it will send local push notification to user, or it is also not possible? – Jprat Oct 14 '11 at 13:02
  • It's been over a year since I tried this, maybe things have changed. Otherwise you can "start" your accelerometer code, when app goes to background due incoming phone call, but your code will not run. iOS does not allow running that kind of code. – JOM Oct 14 '11 at 20:12