Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8469533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:15:19+00:00 2026-06-10T16:15:19+00:00

@interface Tester() { int currentAccelerationOnYaxis; } @end @implementation Tester -(void) test { CMMotionManager *motionManager

  • 0
@interface Tester()
{
    int currentAccelerationOnYaxis;
}    
@end

@implementation Tester

-(void) test
{
    CMMotionManager *motionManager = [[CMMotionManager alloc] init];
    motionManager.deviceMotionUpdateInterval = 0.01;
    [motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue mainQueue]
                                       withHandler:^(CMDeviceMotion *motion, NSError *error)
                                       {
                                           currentAccelerationOnYaxis = motion.userAcceleration.y;
                                       }
    ];
    while(1==1)
    {
        NSLog(@"current acceleration is: %f", currentAccelerationOnYaxis);
    }
}
@end

I then execute the above method on a background thread like this :
[myTester performSelectorInBackground:@selector(test) withObject:nil];

and it works fine.

However, the following configuration is not working and I can’t figure out why :

@implementation MotionHandler

@synthesize accelerationOnYaxis; // this is an int property of the MotionHandler class

-(void) startAccelerationUpdates
{
    CMMotionManager *motionManager = [[CMMotionManager alloc] init];
    motionManager.deviceMotionUpdateInterval = 0.01;
    [motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue mainQueue]
                                       withHandler:^(CMDeviceMotion *motion, NSError *error)
                                       {
                                           self.accelerationOnYaxis = motion.userAcceleration.y;
                                       }
    ];
}

@implementation Tester

-(id)init
{
    //...
    currentMotionHandler = [[MotionHandler alloc] init];
}
-(void) test
{
    [currentMotionHandler startAccelerationUpdates];
    while(1==1)
    {
        NSLog(@"current acceleration is: %f", currentMotionHandler.accelerationOnYaxis);
    }
}
@end

I then execute the above method on a background thread like this :
[myTester performSelectorInBackground:@selector(test) withObject:nil];

and it’s not working, why is that ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:15:20+00:00Added an answer on June 10, 2026 at 4:15 pm

    I figured it out. In my 2nd version the CMMotionManager instance I was creating got lost for some reason. Therefore, I changed the implementation of my MotionHandler class into this :

    MotionHandler.m

    @interface MotionHandler()
    {
       //..
       CMMotionManager *motionManager; // I now declare it here
    }
    
    @implementation MotionHandler
    
    @synthesize accelerationOnYaxis; // this is an int property of the MotionHandler class
    
    -(void) startAccelerationUpdates
    {
        motionManager = [[CMMotionManager alloc] init]; // and then initialize it here..
        motionManager.deviceMotionUpdateInterval = 0.01;
        [motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue mainQueue]
                                           withHandler:^(CMDeviceMotion *motion, NSError *error)
                                           {
                                               self.accelerationOnYaxis = motion.userAcceleration.y;
                                           }
        ];
    }
    -(void)test
    {
        [self startAccelerationUpdates];
        while(1==1)
        {
            NSLog(@"current acceleration on y-axis is: %f", self.accelerationOnYaxis);
        }
    }
    

    and now it seems to be working fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

interface i1{ int test(); } interface i2{ String test(); } class Test implements i1,i2{
I have something that looks like the following: [CoolnessFactor] interface IThing {} class Tester
interface I { int J(); } class A : I { public int J(){return
interface If { ... } class Impl implements If { ... } function test(type:Class,
interface A { void hi(); } class AImpl implements A { public void hi()
interface ICanvasTool { void Motion(Point newLocation); void Tick(); } abstract class CanvasTool_BaseDraw : ICanvasTool
interface Addable<E> { public E add(E x); public E sub(E y); public E zero();
Interface (or an abstract class with all the methods abstract) is a powerful weapon
Generic interface: interface IEntity<TKey, TValue> { TKey Key { get; set; } TValue Value
In Interface Builder, I have a UITableView and I want to place a UIButton

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.