Use of iOS sensors

Source: Internet
Author: User

Reproduced from http://bigbelldev.com/blog/2013/08/05/ios-accelerometer/Big clock Mighty blog iOS involves sensor

Do not check the information, used the iphone's classmates know. There are accelerometer sensors in the iphone that can sense the speed of the phone in which direction, such as screen flipping, flight control games, etc. are made using this feature, and a compass (seemingly called a gyroscope?). ), you can know your direction, and the positioning device, you can know where you are located.

Acceleration sensor related functions are provided by coremotion, compass, location information related functions are provided by corelocation.

Coremotion

In Coremotion.framework, there are the following classes:

1234567     
CMAccelerometerDataCMAttitudeCMDeviceMotionCMGyroDataCMLogItemCMMagnetometerDataCMMotionManager

Everything is done and can be read in the official documentation, not translated here. The realization of the equipment acceleration recognition, mainly using Cmmotionmanager.

Cmmotionmanager

How do I use Cmmotionmanager?

STEP1: Produces an instance of Cmmotionmanager Mmanager.

STEP2: The instance uses the method isaccelerometeravailable to determine whether the accelerometer is available.

STEP3: If available, the sampling frequency is set by method Setaccelerometerupdateinterval.

STEP4: Finally, the sampling is started using Startaccelerometerupdatestoqueue:withhandler and the sampling is processed.

Sample code

In the following code, I implemented a small ball in a box motion, the trajectory of the motion is calculated according to the tilt angle of the mobile phone, the direction of movement is consistent with the tilt angle, and the greater the tilt angle movement speed faster. Code download in the implementation process of the code, the view level has a deeper understanding. In addition, when giving the label to the number of time, found that just use the proxy way, is also the agent has been contacted.

A record of 7788 issues during encoding code sign error:

At the start, draw on this code, at compile time encountered this problem:

Code Sign error: The identity ‘iPhone Developer: Haomian Wang (33P29785DD)‘ doesn‘t match any valid certificate/private key pair in the default keychain

Reason:

Codesigning signed not your provisioning, can not be used on the real machine.

Workaround:

In the targets build settings, find the Code Signing Identity, which is not their own developer changed to their own provisioning.

Note:

The code used for reference is to use the Acceleroimeter:didaccelerate method to process the captured acceleration information, but this method has been deprecated in iOS5 and is now implemented using the Coremotion framework.

Coremotion.framework not added

When compiling your own code, the following error occurred first:

Reason:

The reason is that coremotion is used in the code, but Coremotion.framework is not added to the project. This is common: when using the framework such as corelocation, you also want to add the framework to your project.

Workaround: add coremotion.framework at Place

Change the name of the project to cause compilation.

This is a digression, at that time wanted to change the project name, the results changed, but compiled. Reason:

The cause is a name, a path change that causes the file to be found.

Workaround:

Notice the name of the word three points:

    1. After you have modified project's name, Xcode will prompt you to change some other places as well, and you will be prompted to modify it.
    2. Also change the name of the local folder, note that the files in the Xcode project file list filename will change to red, if it is red, you need to find ways to re-add the path;
    3. Buildsettings in the project, it's best to search your original name and make changes. The compilation I came across is still the original name and has not been changed.

Use of iOS sensors

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.