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 6952281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:19:43+00:00 2026-05-27T14:19:43+00:00

I am trying to initialize the CMMotionManager so start updates and create a reference

  • 0

I am trying to initialize the CMMotionManager so start updates and create a reference attitude matrix, and then when i click a button trough the storyboard, i display a different screen (which is in a viewcontroller) and i want to use the reference attitude matrix and other readings from the motion manager but if I do a simple check to see if its ready it says it isnt (even thought it was ready on the previous screen).

So I was researching a little bit and i came across some standford notes that say it is a global resource so that it is ok to either use delegates or classes, that got me thinking.

If i use a delegate then technically the owner of the resource is doing the action for me right? so it doesnt really mean it is global.

What about classes? i tried implementing a MotionManager Class but i still didnt get any readings on the second screen… and i just didnt initialize it again on the new screen because i dont want to have multiple instances runing at the same time.

To solve my problem i also suppose i could initialize it once in the main one, save the attitude, pass it to the next one in a segue transition and just re initialize the motion manager so i only have 1 instance (or close old one on screen will dissapear).

But i do not want this because the user might click right away on the screen and the motion manager does take a little bit of time to initialize (or thats what i noticed).

Thanks in advance for any help you can provide.

EDIT:

Ok i tried the delegate method and i still cant read from the device manager in the second window. What comes to mind is that MAYBE when I am going to the second window xcode is automaticaly releasing my instance of Motion manager…. (CMMotionManager).

Anyone knows how to check this?

  • 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-05-27T14:19:44+00:00Added an answer on May 27, 2026 at 2:19 pm

    I hope I understood you right. Then I suggest using a singleton design pattern encapsulating motion manager access in a specialised class. Some pseudo code:

    MotionHandler.h

    @interface MotionHandler {
        CMMotionManager* motionManager;
    
        + (MotionHandler*) getInstance;
    }
    

    MotionHandler.c:

    @interface MotionHandler {
    
        static MotionHandler* instance;
    
        + (MotionHandler*) getInstance {
            if (instance == nil) {
                instance = [[self alloc] init];
            }
            return instance;
        }
    
        - (id)init {
            if ((self = [super init])) {
                motionManager = [[CMMotionManager alloc] init];
                // initialise CMMotionManager
            }
        }
    }
    

    So there is one instance of MotionHandler only which manages access to CMMotionManager. You can accesss your CMMotionManager instance from everywhere with MotionHandler.getInstance.motionManager.

    If you need access to CoreMotion from several classes, I recommend total encapsulation of CMMotionManager access. That means make it @private and provide methods like getDeviceMotion, setReferenceAttitude, …
    This helps to avoid complications like starting it twice or access to CMDeviceMotion before start and makes it more convenient to debug.

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

Sidebar

Related Questions

I'm trying to initialize a static class, with an argument, and then run some
I am trying to initialize a JScrollPane to start life at the bottom. I
I am trying to initialize a class variable as a hash when I create
I'm trying to initialize a session but i get this error: Warning: session_start() [function.session-start]:
I am trying to initialize a reference object through the initialization list in the
i'm trying to initialize all cells of a matrix with NULL values, but something
I'm trying to initialize a variable as a float and then add to it
I am trying to initialize my controls in Silverlight. I am looking for something
I'm trying to initialize string with iterators and something like this works: ifstream fin(tmp.txt);
Edited again because it originally wasn't clear that I'm trying to initialize the arrays

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.