Gold field
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 <CoreLocation/CoreLocation>
Detection method
+ (Clauthorizationstatus) authorizationstatus
Related return parameters
The user has not made a selection kclauthorizationstatusnotdetermined = 0,//is not authorized and the user cannot be updated, such as parental Controls kclauthorizationstatusrestricted,// The user rejects the app using kclauthorizationstatusdenied,//always using 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 (Dispatch_time_now, (int64_t) (0.5 * nsec_per_sec)), Dispatch_get_main_queue (), ^{ Checklocationauth (); }); }; Checklocationauth ();
2. Contacts
#import <AddressBook/AddressBook.h>
Detection method
Abauthorizationstatus abaddressbookgetauthorizationstatus (void)
Authorization status
kabauthorizationstatusnotdetermined = 0, //No authorization selected
kabauthorizationstatusrestricted, //unauthorized, and user cannot update, such as parental control case
Kabauthorizationstatusdenied, //user denied app use
Kabauthorizationstatusauthorized //authorized, available with
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 authorization
#import <EventKit/EventKit.h>
Detection method
+ (Ekauthorizationstatus) Authorizationstatusforentitytype: (Ekentitytype) EntityType
Parameter type
Ekentitytypeevent, Ekentitytypereminder
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 Authorizationstatusforentitytype:ekentitytypeevent]; if (ekauthorizationstatusauthorized = = 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 (), ^{ Checkcalanderauth (); }); } }; Checkcalanderauth ();
Not to be continued ...
All rights reserved, reprint must indicate the author (jintian) and original source (original).
Authorization detection for IOS location services, contacts, calendars, reminders, photos, Bluetooth sharing, microphones, cameras, and more