IOS Hardware Licensing Detection: Location services, contacts, calendars, reminders, photos, Bluetooth sharing, microphones, cameras, etc. (RPM)

Source: Internet
Author: User

Reprinted from: http://www.cocoachina.com/ios/20151214/14502.html

iOS system version of the premise of the continuous upgrade, along with the user to use the security of the device, iOS system for the app needs to use more stringent hardware restrictions, app processing a little inappropriate, the user is not aware of the function is not available, heavy will cause the app Crash.

When the user in the app launch, see the bullet out of the "XXX request access to your location" "XXX request access to your address book" "XXX request access to your Calendar" "XXX request access to your webcam" and other series of messages, users feel impatient while, will also be due to a temporary security considerations and the corresponding function to shield off, this is just the beginning, when the user really in the use of the corresponding function, there will be a continuous strange phenomenon, such as data display anomalies: There is information in the Address book, but always loading data, and some even direct crash.

Below, the author will comprehensively put the above hardware authorization detection, one by one detailed list, and give the relevant sample code:

1. Location Services

Related frameworks

#import

Detection method

+ (Clauthorizationstatus) authorizationstatus

Related return parameters

User has not made a selection kclauthorizationstatusnotdetermined = 0,//unauthorized, and user cannot update, such as parental control kclauthorizationstatusrestricted,// The user rejects the app using kclauthorizationstatusdenied,//Always uses kclauthorizationstatusauthorizedalways ns_enum_available (NA, 8_0),// On-demand use of Kclauthorizationstatusauthorizedwheninuse ns_enum_available (NA, 8_0),//Authorized kclauthorizationstatusauthorized

Reference Code

__block void (^checklocationauth) (void) = ^{Clauthorizationstatus authstatus = [Cllocationmanager authorizationStatus         ]; if (clauthorizationstatusauthorized = = Authstatus) {//authorization succeeded, perform subsequent operations}else {dispatch_after (Dispatch_time (D        Ispatch_time_now, (int64_t) (0.5 * nsec_per_sec)), Dispatch_get_main_queue (), ^{Checklocationauth ();    }); }};checklocationauth ();

2. Contacts

#import

Detection method

Abauthorizationstatus abaddressbookgetauthorizationstatus (void)

Authorization status

kabauthorizationstatusnotdetermined = 0,//no authorization selected kabauthorizationstatusrestricted,//unauthorized, and user cannot update, such as parental control case K Abauthorizationstatusdenied,//user denied app use kabauthorizationstatusauthorized//authorized, can use

Reference Code

__block void (^checkaddressbookauth) (void) = ^{Abauthorizationstatus Authstatus = abaddressbookgetauthorizationstatus         (); if (kabauthorizationstatusauthorized = = Authstatus) {//authorization succeeded, perform subsequent operations}else {Dispatch_after (Dispatch_time (        Dispatch_time_now, (int64_t) (0.5 * nsec_per_sec)), Dispatch_get_main_queue (), ^{Checkaddressbookauth ();    }); }};checkaddressbookauth ();

3. Calendar/Reminders Authorization

#import

Detection method

+ (Ekauthorizationstatus) Authorizationstatusforentitytype: (Ekentitytype) EntityType

Parameter type

Ekentitytypeevent,//Event ekentitytypereminder//Reminders

Authorization status

ekauthorizationstatusnotdetermined = 0,//Not authorized to select ekauthorizationstatusrestricted,//unauthorized, and user cannot update, such as parental control case Ekauthorizationstatusdenied,//user denied app use ekauthorizationstatusauthorized,//authorized, can use

Reference Code

__block void (^checkcalanderauth) (void) = ^{Ekauthorizationstatus authstatus = [Ekauthorizationstatus authorizationSta         Tusforentitytype:ekentitytypeevent]; if (ekauthorizationstatusauthorized = = Authstatus) {//authorization succeeded, perform subsequent operations}else {dispatch_after (Dispatch_time (D        Ispatch_time_now, (int64_t) (0.5 * nsec_per_sec)), Dispatch_get_main_queue (), ^{Checkcalanderauth ();    }); }};checkcalanderauth ();

4. Photo Library Authorization

#import

Detection method

+ (alauthorizationstatus) authorizationstatus;

Authorization status

alauthorizationstatusnotdetermined = 0,//Not authorized to select alauthorizationstatusrestricted,//unauthorized, and user cannot update, such as parental control case Alauthorizationstatusdenied,//user denied app use alauthorizationstatusauthorized,//authorized, can use

Reference Code

__block void (^checkassetlibraryauth) (void) = ^{Alauthorizationstatus authstatus = [Alauthorizationstatus authorizatio         Nstatus]; if (alauthorizationstatusauthorized = = Authstatus) {//authorization succeeded, perform subsequent operations}else {dispatch_after (Dispatch_time (D        Ispatch_time_now, (int64_t) (0.5 * nsec_per_sec)), Dispatch_get_main_queue (), ^{Checkassetlibraryauth ();    }); }};checkassetlibraryauth ();

5. Bluetooth Authorization status detection

#import

Detection method

+ (cbperipheralmanagerauthorizationstatus) authorizationstatus;

Authorization status

cbperipheralmanagerauthorizationstatusnotdetermined = 0,//Not authorized to select cbperipheralmanagerauthorizationstatusrestricted,//unauthorized, and user cannot update, such as parental control case Cbperipheralmanagerauthorizationstatusdenied,//user denied app use cbperipheralmanagerauthorizationstatusauthorized,//has Authorization, you can use

Reference Code

__block void (^checkperipheralauth) (void) = ^{Cbperipheralmanagerauthorizationstatus authstatus = [CBPeripheralManage         Rauthorizationstatus Authorizationstatus]; if (cbperipheralmanagerauthorizationstatusauthorized = = Authstatus) {//authorization succeeded, perform subsequent operations}else {Dispatch_afte R (Dispatch_time (Dispatch_time_now, (int64_t) (0.5 * nsec_per_sec)), Dispatch_get_main_queue (), ^{Checkperiphera        Lauth ();    }); }};checkperipheralauth ();

6, Camera authorization status detection

#import

Detection method

+ (Avauthorizationstatus) Authorizationstatusformediatype: (NSString *) mediatype;

Authorization status

avauthorizationstatusnotdetermined = 0,//Not authorized to select avauthorizationstatusrestricted,//unauthorized, and user cannot update, such as parental control case Avauthorizationstatusdenied,//user denied app use avauthorizationstatusauthorized,//authorized, can use

Reference Code

__block void (^checkcameraauth) (void) = ^{Avauthorizationstatus authstatus = [Avauthorizationstatus AuthorizationStatu         Sformediatype:avmediatypevideo]; if (avauthorizationstatusauthorized = = Authstatus) {//authorization succeeded, perform subsequent operations}else {dispatch_after (Dispatch_time (D        Ispatch_time_now, (int64_t) (0.5 * nsec_per_sec)), Dispatch_get_main_queue (), ^{Checkcameraauth ();    }); }};checkcameraauth ();

7, Microphone authorization status detection

#import

Detection method

-(avaudiosessionrecordpermission) recordpermission;

Authorization status

avaudiosessionrecordpermissionundetermined,//The user has not been requested permission. Avaudiosessionrecordpermissiondenied,//The user has been requested and has refused permission. avaudiosessionrecordpermissiongranted,//The user has been requested and granted permission.

Reference Code

__block void (^checkrecordpermission) (void) = ^{avaudiosessionrecordpermission authstatus = [[Avaudiosession sharedIns         Tance] recordpermission]; if (avaudiosessionrecordpermissiongranted = = Authstatus) {//authorization succeeded, perform subsequent operations}else {dispatch_after (Dispatch_        Time (Dispatch_time_now, (int64_t) (0.5 * nsec_per_sec)), Dispatch_get_main_queue (), ^{checkrecordpermission ();    }); }};checkrecordpermission ();

IOS Hardware Licensing Detection: Location services, contacts, calendars, reminders, photos, Bluetooth sharing, microphones, cameras, etc. (RPM)

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.