iOS開發(fā)檢測是否開啟定位、是否允許消息推送等權限

1.iOS開發(fā)檢測是否開啟定位:

需要導入:

#import


代碼如下:

+ (void)openLocationServiceWithBlock:(ReturnBlock)returnBlock

{

? ? BOOL isOPen = NO;

? ? if ([CLLocationManager locationServicesEnabled] && [CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied) {

? ? ? ? isOPen = YES;

? ? }

? ? if (returnBlock) {

? ? ? ? returnBlock(isOpen);

? ? }

}


2.iOS開發(fā)檢測是否允許消息推送:

需要導入:

#import


代碼如下:

+ (void)openMessageNotificationServiceWithBlock:(ReturnBlock)returnBlock

{

? ? BOOL isOpen = NO;

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0

? ? UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];

? ? if (setting.types != UIUserNotificationTypeNone) {

? ? ? ? isOpen = YES;

? ? }

#else

? ? UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

? ? if (type != UIRemoteNotificationTypeNone) {

? ? ? ? isOpen = YES;

? ? }

#endif

? ? if (returnBlock) {

? ? ? ? returnBlock(isOpen);

? ? }

}



+ (void)openMessageNotificationServiceWithBlock:(ReturnBlock)returnBlock

{

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0

? ? [[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings *settings) {

? ? ? ? if (returnBlock) {

? ? ? ? ? ? returnBlock(settings.authorizationStatus == UNAuthorizationStatusAuthorized);

? ? ? ? }

? ? }];

#elif __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0

? ? returnBlock([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]);

#else

? ? UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

? ? if (returnBlock) {

? ? ? ? returnBlock(type != UIRemoteNotificationTypeNone);

? ? }

#endif

}


3.iOS開發(fā)檢測是否開啟攝像頭:

需要導入:

#import


代碼如下:

+ (void)openCaptureDeviceServiceWithBlock:(ReturnBlock)returnBlock

{

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0

? ? AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];

? ? if (authStatus == AVAuthorizationStatusNotDetermined) {

? ? ? ? [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {

? ? ? ? ? ? if (returnBlock) {

? ? ? ? ? ? ? ? returnBlock(granted);

? ? ? ? ? ? }

? ? ? ? }];

? ? ? ? return NO;

? ? } else if (authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) {

? ? ? ? returnBlock(NO);

? ? } else {

? ? ? ? returnBlock(YES);

? ? }

#endif

}


4.iOS開發(fā)檢測是否開啟相冊:

需要導入:

#import #import


代碼如下:

+ (void)openAlbumServiceWithBlock:(ReturnBlock)returnBlock

{

? ? BOOL isOpen;

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0

? ? PHAuthorizationStatus authStatus = [PHPhotoLibrary authorizationStatus];

? ? isOpen = YES;

? ? if (authStatus == PHAuthorizationStatusRestricted || authStatus == PHAuthorizationStatusDenied) {

? ? ? ? isOpen = NO;

? ? }

#else

? ? ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];

? ? isOpen = YES;

? ? if (author == ALAuthorizationStatusRestricted || author == ALAuthorizationStatusDenied) {

? ? ? ? isOpen = NO;

? ? }

#endif

? ? if (returnBlock) {

? ? ? ? returnBlock(isOpen);

? ? }

}


5.iOS開發(fā)檢測是否開啟麥克風:

需要導入:

#import


代碼如下:

+ (void)openRecordServiceWithBlock:(ReturnBlock)returnBlock

{

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0

? ? AVAudioSessionRecordPermission permissionStatus = [[AVAudioSession sharedInstance] recordPermission];

? ? if (permissionStatus == AVAudioSessionRecordPermissionUndetermined) {

? ? ? ? [[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {

? ? ? ? ? ? if (returnBlock) {

? ? ? ? ? ? ? ? returnBlock(granted);

? ? ? ? ? ? }

? ? ? ? }];

? ? } else if (permissionStatus == AVAudioSessionRecordPermissionDenied) {

? ? ? ? returnBlock(NO);

? ? } else {

? ? ? ? returnBlock(YES);

? ? }

#endif

}


6.iOS開發(fā)檢測是否開啟通訊錄:

需要導入:

#import #import


代碼如下:

+ (void)openContactsServiceWithBolck:(ReturnBlock)returnBolck

{

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0

? ? CNAuthorizationStatus cnAuthStatus = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];

? ? if (cnAuthStatus == CNAuthorizationStatusNotDetermined) {

? ? ? ? CNContactStore *store = [[CNContactStore alloc] init];

? ? ? ? [store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError *error) {

? ? ? ? ? ? if (returnBolck) {

? ? ? ? ? ? ? ? returnBolck(granted);

? ? ? ? ? ? }

? ? ? ? }];

? ? } else if (cnAuthStatus == CNAuthorizationStatusRestricted || cnAuthStatus == CNAuthorizationStatusDenied) {

? ? ? ? if (returnBolck) {

? ? ? ? ? ? returnBolck(NO);

? ? ? ? }

? ? } else {

? ? ? ? if (returnBolck) {

? ? ? ? ? ? returnBolck(YES);

? ? ? ? }

? ? }

#else

? ? //ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);

? ? ABAddressBookRef addressBook = ABAddressBookCreate();

? ? ABAuthorizationStatus authStatus = ABAddressBookGetAuthorizationStatus();

? ? if (authStatus != kABAuthorizationStatusAuthorized) {

? ? ? ? ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {

? ? ? ? ? ? dispatch_async(dispatch_get_main_queue(), ^{

? ? ? ? ? ? ? ? if (error) {

? ? ? ? ? ? ? ? ? ? NSLog(@"Error: %@", (__bridge NSError *)error);

? ? ? ? ? ? ? ? ? ? if (returnBolck) {

? ? ? ? ? ? ? ? ? ? ? ? returnBolck(NO);

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? ? ? if (returnBolck) {

? ? ? ? ? ? ? ? ? ? ? ? returnBolck(YES);

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? }

? ? ? ? ? ? });

? ? ? ? });

? ? } else {

? ? ? ? if (returnBolck) {

? ? ? ? ? ? returnBolck(YES);

? ? ? ? }

? ? }

#endif

}


7.iOS開發(fā)檢測是否開啟藍牙:

需要導入:

#import


代碼如下:

+ (void)openPeripheralServiceWithBolck:(ReturnBlock)returnBolck

{

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_7_0

? ? CBPeripheralManagerAuthorizationStatus cbAuthStatus = [CBPeripheralManager authorizationStatus];

? ? if (cbAuthStatus == CBPeripheralManagerAuthorizationStatusNotDetermined) {

? ? ? ? if (returnBolck) {

? ? ? ? ? ? returnBolck(NO);

? ? ? ? }

? ? } else if (cbAuthStatus == CBPeripheralManagerAuthorizationStatusRestricted || cbAuthStatus == CBPeripheralManagerAuthorizationStatusDenied) {

? ? ? ? if (returnBolck) {

? ? ? ? ? ? returnBolck(NO);

? ? ? ? }

? ? } else {

? ? ? ? if (returnBolck) {

? ? ? ? ? ? returnBolck(YES);

? ? ? ? }

? ? }

#endif

}


8.iOS開發(fā)檢測是否開啟日歷/備忘錄:

需要導入:

#import


代碼如下:

+ (void)openEventServiceWithBolck:(ReturnBlock)returnBolck withType:(EKEntityType)entityType

{

? ? // EKEntityTypeEvent? ? 代表日歷

? ? // EKEntityTypeReminder 代表備忘

? ? EKAuthorizationStatus ekAuthStatus = [EKEventStore authorizationStatusForEntityType:entityType];

? ? if (ekAuthStatus == EKAuthorizationStatusNotDetermined) {

? ? ? ? EKEventStore *store = [[EKEventStore alloc] init];

? ? ? ? [store requestAccessToEntityType:entityType completion:^(BOOL granted, NSError *error) {

? ? ? ? ? ? if (returnBolck) {

? ? ? ? ? ? ? ? returnBolck(granted);

? ? ? ? ? ? }

? ? ? ? }];

? ? } else if (ekAuthStatus == EKAuthorizationStatusRestricted || ekAuthStatus == EKAuthorizationStatusDenied) {

? ? ? ? if (returnBolck) {

? ? ? ? ? ? returnBolck(NO);

? ? ? ? }

? ? } else {

? ? ? ? if (returnBolck) {

? ? ? ? ? ? returnBolck(YES);

? ? ? ? }

? ? }

}

9.iOS開發(fā)檢測是否開啟聯(lián)網(wǎng):

需要導入:

#import


代碼如下:

+ (void)openEventServiceWithBolck:(ReturnBlock)returnBolck

{

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0

? ? CTCellularData *cellularData = [[CTCellularData alloc] init];

? ? cellularData.cellularDataRestrictionDidUpdateNotifier = ^(CTCellularDataRestrictedState state){

? ? ? ? if (state == kCTCellularDataRestrictedStateUnknown || state == kCTCellularDataNotRestricted) {

? ? ? ? ? ? if (returnBolck) {

? ? ? ? ? ? ? ? returnBolck(NO);

? ? ? ? ? ? }

? ? ? ? } else {

? ? ? ? ? ? if (returnBolck) {

? ? ? ? ? ? ? ? returnBolck(YES);

? ? ? ? ? ? }

? ? ? ? }

? ? };

? ? CTCellularDataRestrictedState state = cellularData.restrictedState;

? ? if (state == kCTCellularDataRestrictedStateUnknown || state == kCTCellularDataNotRestricted) {

? ? ? ? if (returnBolck) {

? ? ? ? ? ? returnBolck(NO);

? ? ? ? }

? ? } else {

? ? ? ? if (returnBolck) {

? ? ? ? ? ? returnBolck(YES);

? ? ? ? }

? ? }

#endif

}

10.iOS開發(fā)檢測是否開啟健康:

需要導入:

#import


代碼如下:

+ (void)openHealthServiceWithBolck:(ReturnBlock)returnBolck

{

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0

? ? if (![HKHealthStore isHealthDataAvailable]) {

? ? ? ? if (returnBolck) {

? ? ? ? ? ? returnBolck(NO);

? ? ? ? }

? ? } else {

? ? ? ? HKHealthStore *healthStore = [[HKHealthStore alloc] init];

? ? ? ? HKObjectType *hkObjectType = [HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight];

? ? ? ? HKAuthorizationStatus hkAuthStatus = [healthStore authorizationStatusForType:hkObjectType];

? ? ? ? if (hkAuthStatus == HKAuthorizationStatusNotDetermined) {

? ? ? ? ? ? // 1. 你創(chuàng)建了一個NSSet對象,里面存有本篇教程中你將需要用到的從Health Stroe中讀取的所有的類型:個人特征(血液類型、性別、出生日期)、數(shù)據(jù)采樣信息(身體質(zhì)量、身高)以及鍛煉與健身的信息。

? ? ? ? ? ? NSSet * healthKitTypesToRead = [[NSSet alloc] initWithArray:@[[HKObjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierDateOfBirth],[HKObjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierBloodType],[HKObjectType characteristicTypeForIdentifier:HKCharacteristicTypeIdentifierBiologicalSex],[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMass],[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight],[HKObjectType workoutType]]];

? ? ? ? ? ? // 2. 你創(chuàng)建了另一個NSSet對象,里面有你需要向Store寫入的信息的所有類型(鍛煉與健身的信息、BMI、能量消耗、運動距離)

? ? ? ? ? ? NSSet * healthKitTypesToWrite = [[NSSet alloc] initWithArray:@[[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierBodyMassIndex],[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierActiveEnergyBurned],[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceWalkingRunning],[HKObjectType workoutType]]];

? ? ? ? ? ? [healthStore requestAuthorizationToShareTypes:healthKitTypesToWrite readTypes:healthKitTypesToRead completion:^(BOOL success, NSError *error) {

? ? ? ? ? ? ? ? if (returnBolck) {

? ? ? ? ? ? ? ? ? ? returnBolck(success);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }];

? ? ? ? } else if (hkAuthStatus == HKAuthorizationStatusSharingDenied) {

? ? ? ? ? ? if (returnBolck) {

? ? ? ? ? ? ? ? returnBolck(NO);

? ? ? ? ? ? }

? ? ? ? } else {

? ? ? ? ? ? if (returnBolck) {

? ? ? ? ? ? ? ? returnBolck(YES);

? ? ? ? ? ? }

? ? ? ? }

? ? }

#endif

}


11.iOS開發(fā)檢測是否開啟Touch ID:

需要導入:

#import


代碼如下:

#pragma mark - 開啟Touch ID服務

+ (void)openTouchIDServiceWithBlock:(ReturnBlock)returnBlock

{

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0

? ? LAContext *laContext = [[LAContext alloc] init];

? ? laContext.localizedFallbackTitle = @"輸入密碼";

? ? NSError *error;

? ? if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {

? ? ? ? NSLog(@"恭喜,Touch ID可以使用!");

? ? ? ? [laContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"需要驗證您的指紋來確認您的身份信息" reply:^(BOOL success, NSError *error) {

? ? ? ? ? ? if (success) {

? ? ? ? ? ? ? ? // 識別成功

? ? ? ? ? ? ? ? if (returnBlock) {

? ? ? ? ? ? ? ? ? ? [[NSOperationQueue mainQueue] addOperationWithBlock:^{

? ? ? ? ? ? ? ? ? ? ? ? returnBlock(YES);

? ? ? ? ? ? ? ? ? ? }];

? ? ? ? ? ? ? ? }

? ? ? ? ? ? } else if (error) {

? ? ? ? ? ? ? ? if (returnBlock) {

? ? ? ? ? ? ? ? ? ? [[NSOperationQueue mainQueue] addOperationWithBlock:^{

? ? ? ? ? ? ? ? ? ? ? ? returnBlock(NO);

? ? ? ? ? ? ? ? ? ? }];

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? if (error.code == LAErrorAuthenticationFailed) {

? ? ? ? ? ? ? ? ? ? // 驗證失敗

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? if (error.code == LAErrorUserCancel) {

? ? ? ? ? ? ? ? ? ? // 用戶取消

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? if (error.code == LAErrorUserFallback) {

? ? ? ? ? ? ? ? ? ? // 用戶選擇輸入密碼

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? if (error.code == LAErrorSystemCancel) {

? ? ? ? ? ? ? ? ? ? // 系統(tǒng)取消

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? if (error.code == LAErrorPasscodeNotSet) {

? ? ? ? ? ? ? ? ? ? // 密碼沒有設置

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? }];

? ? } else {

? ? ? ? NSLog(@"設備不支持Touch ID功能,原因:%@",error);

? ? ? ? if (returnBlock) {

? ? ? ? ? ? returnBlock(NO);

? ? ? ? }

? ? }

#endif

}


12.iOS開發(fā)檢測是否開啟Apple Pay:

需要導入:

#import


代碼如下:

#pragma mark - 開啟Apple Pay服務

+ (void)openApplePayServiceWithBlock:(ReturnBlock)returnBlock

{

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_0

? ? NSArray *supportedNetworks = @[PKPaymentNetworkAmex, PKPaymentNetworkMasterCard, PKPaymentNetworkVisa, PKPaymentNetworkDiscover];

? ? if ([PKPaymentAuthorizationViewController canMakePayments] && [PKPaymentAuthorizationViewController canMakePaymentsUsingNetworks:supportedNetworks]) {

? ? ? ? if (returnBlock) {

? ? ? ? ? ? returnBlock(YES);

? ? ? ? }

? ? } else {

? ? ? ? if (returnBlock) {

? ? ? ? ? ? returnBlock(NO);

? ? ? ? }

? ? }

#endif

}

13.iOS開發(fā)檢測是否開啟語音識別:

需要導入:

#import


代碼如下:

#pragma mark - 開啟語音識別服務

+ (void)openSpeechServiceWithBlock:(ReturnBlock)returnBlock

{

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0

? ? SFSpeechRecognizerAuthorizationStatus speechAuthStatus = [SFSpeechRecognizer authorizationStatus];

? ? if (speechAuthStatus == SFSpeechRecognizerAuthorizationStatusNotDetermined) {

? ? ? ? [SFSpeechRecognizer requestAuthorization:^(SFSpeechRecognizerAuthorizationStatus status) {

? ? ? ? ? ? if (status == SFSpeechRecognizerAuthorizationStatusAuthorized) {

? ? ? ? ? ? ? ? dispatch_async(dispatch_get_main_queue(), ^{

? ? ? ? ? ? ? ? ? ? if (returnBlock) {

? ? ? ? ? ? ? ? ? ? ? ? returnBlock(YES);

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? });

? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? dispatch_async(dispatch_get_main_queue(), ^{

? ? ? ? ? ? ? ? ? ? if (returnBlock) {

? ? ? ? ? ? ? ? ? ? ? ? returnBlock(YES);

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? });

? ? ? ? ? ? }

? ? ? ? }];

? ? } else if (speechAuthStatus == SFSpeechRecognizerAuthorizationStatusAuthorized) {

? ? ? ? if (returnBlock) {

? ? ? ? ? ? returnBlock(YES);

? ? ? ? }

? ? } else{

? ? ? ? if (returnBlock) {

? ? ? ? ? ? returnBlock(NO);

? ? ? ? }

? ? }

#endif

}

14.iOS開發(fā)檢測是否開啟媒體資料庫/Apple Music:

需要導入:

#import


代碼如下:

#pragma mark - 開啟媒體資料庫/Apple Music 服務

+ (void)openMediaPlayerServiceWithBlock:(ReturnBlock)returnBlock

{

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_9_3

? ? MPMediaLibraryAuthorizationStatus authStatus = [MPMediaLibrary authorizationStatus];

? ? if (authStatus == MPMediaLibraryAuthorizationStatusNotDetermined) {

? ? ? ? [MPMediaLibrary requestAuthorization:^(MPMediaLibraryAuthorizationStatus status) {

? ? ? ? ? ? if (status == MPMediaLibraryAuthorizationStatusAuthorized) {

? ? ? ? ? ? ? ? dispatch_async(dispatch_get_main_queue(), ^{

? ? ? ? ? ? ? ? ? ? if (returnBlock) {

? ? ? ? ? ? ? ? ? ? ? ? returnBlock(YES);

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? });

? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? dispatch_async(dispatch_get_main_queue(), ^{

? ? ? ? ? ? ? ? ? ? if (returnBlock) {

? ? ? ? ? ? ? ? ? ? ? ? returnBlock(NO);

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? });

? ? ? ? ? ? }

? ? ? ? }];

? ? }else if (authStatus == MPMediaLibraryAuthorizationStatusAuthorized){

? ? ? ? if (returnBlock) {

? ? ? ? ? ? returnBlock(YES);

? ? ? ? }

? ? }else{

? ? ? ? if (returnBlock) {

? ? ? ? ? ? returnBlock(NO);

? ? ? ? }

? ? }

#endif

}

15.iOS開發(fā)檢測是否開啟Siri:

需要導入:

#import


代碼如下:

#pragma mark - 開啟Siri服務

+ (void)openSiriServiceWithBlock:(ReturnBlock)returnBlock

{

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0

? ? INSiriAuthorizationStatus siriAutoStatus = [INPreferences siriAuthorizationStatus];

? ? if (siriAutoStatus == INSiriAuthorizationStatusNotDetermined) {

? ? ? ? [INPreferences requestSiriAuthorization:^(INSiriAuthorizationStatus status) {

? ? ? ? ? ? if (status == INSiriAuthorizationStatusAuthorized) {

? ? ? ? ? ? ? ? dispatch_async(dispatch_get_main_queue(), ^{

? ? ? ? ? ? ? ? ? ? if (returnBlock) {

? ? ? ? ? ? ? ? ? ? ? ? returnBlock(YES);

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? });

? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? dispatch_async(dispatch_get_main_queue(), ^{

? ? ? ? ? ? ? ? ? ? if (returnBlock) {

? ? ? ? ? ? ? ? ? ? ? ? returnBlock(YES);

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? });

? ? ? ? ? ? }

? ? ? ? }];

? ? } else if (siriAutoStatus == INSiriAuthorizationStatusAuthorized) {

? ? ? ? if (returnBlock) {

? ? ? ? ? ? returnBlock(YES);

? ? ? ? }

? ? } else{

? ? ? ? if (returnBlock) {

? ? ? ? ? ? returnBlock(NO);

? ? ? ? }

? ? }

#endif

}


在.h文件中申明block


#if NS_BLOCKS_AVAILABLE

typedef void(^ReturnBlock)(BOOL isOpen);

#endif


由于iOS10的權限原因,需要在工程的info.plist(右擊選擇Open as - Source Code)中添加



NSPhotoLibraryUsageDescription

App需要您的同意,才能訪問相冊


NSCameraUsageDescription

App需要您的同意,才能訪問相機


NSMicrophoneUsageDescription

App需要您的同意,才能訪問麥克風


NSLocationUsageDescription

App需要您的同意,才能訪問位置


NSLocationWhenInUseUsageDescription

App需要您的同意,才能在使用期間訪問位置


NSLocationAlwaysUsageDescription

App需要您的同意,才能始終訪問位置


NSCalendarsUsageDescription

App需要您的同意,才能訪問日歷


NSRemindersUsageDescription

App需要您的同意,才能訪問提醒事項


NSMotionUsageDescription

App需要您的同意,才能訪問運動與健身


NSHealthUpdateUsageDescription

App需要您的同意,才能訪問健康更新


NSHealthShareUsageDescription

App需要您的同意,才能訪問健康分享


NSBluetoothPeripheralUsageDescription

App需要您的同意,才能訪問藍牙


NSAppleMusicUsageDescription

App需要您的同意,才能訪問媒體資料庫


NSSpeechRecognitionUsageDescription

App需要您的同意,才能使用語音識別

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容