Device-specific development for IOS: Check device proximity and battery status

Source: Internet
Author: User

The Uidevice class provides APIs that enable you to track the characteristics of your device, including battery status and proximity sensors. Both of them provide updates in the form of notifications that they can subscribe to notify your application when there are important updates.

1) Start and disable proximity sensors

Proximity is an iphone-specific feature at this point. IPod Touch and ipad do not offer proximity sensors. There is little benefit from using proximity sensors unless there is some compelling reason to hold the iphone relative to the body part (or vice versa).

When the proximity sensor is enabled, it has a primary task. He will detect if there are larger objects in front of them. If it is, he will turn off the screen and send a regular notification. Moving the blocked object away will open the screen again.

The following example shows how proximity sensing is handled on the iphone. His code uses the Uidevice class to switch proximity monitoring, and subscribes to Uideviceproximitystatedidchangenotification to capture state changes. Both states are on and off. When the Uidevice Proximitystate property returns Yes, the proximity sensor is activated.

2 "Monitoring battery status

Device-specific development for IOS: Check device proximity and battery status

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.