欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

iOS應用部分權限控制-創(chuàng)新互聯(lián)

整理下iOS開發(fā)中常用的權限控制,只整理里一些常用的并不全。

創(chuàng)新互聯(lián)-專業(yè)網站定制、快速模板網站建設、高性價比平湖網站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式平湖網站制作公司更省心,省錢,快速模板網站建設找我們,業(yè)務覆蓋平湖地區(qū)。費用合理售后完善,十年實體公司更值得信賴。
#import <Foundation/Foundation.h>

typedef void (^AuthorizedFinishBlock)();

@interface LYAuthorizedMaster : NSObject


#pragma mark - 攝像頭權限
+(BOOL)checkCameraAuthority;
+(void)cameraAuthorityCheckSuccess:(AuthorizedFinishBlock)_success fail:(AuthorizedFinishBlock)_fail;

#pragma mark - 麥克風權限
+(BOOL)checkAudioAuthority;
+(void)audioAuthorityCheckSuccess:(AuthorizedFinishBlock)_success fail:(AuthorizedFinishBlock)_fail;

#pragma mark - 相冊權限
+(BOOL)checkAlbumAuthority;
+(void)albumAuthorityCheckSuccess:(AuthorizedFinishBlock)_success fail:(AuthorizedFinishBlock)_fail;

#pragma mark - 推送通知權限
+(BOOL)checkPushNotificationAuthority;
+(void)pushNotificationAuthorityCheckSuccess:(AuthorizedFinishBlock)_success fail:(AuthorizedFinishBlock)_fail;

#pragma mark - 推送通知權限
+(BOOL)checkLocationAuthority;
+(void)locationAuthorityCheckSuccess:(AuthorizedFinishBlock)_success fail:(AuthorizedFinishBlock)_fail;

#pragma mark - 通訊錄權限
+(BOOL)checkAddressBookAuthority;
+(void)AddressBookAuthorityCheckSuccess:(AuthorizedFinishBlock)_success fail:(AuthorizedFinishBlock)_fail;

下面是.m文件

里面引入了很多庫文件,也不是所用項目都會用到的,用不到的注掉就好。

#import "LYAuthorizedMaster.h"
#import <AVFoundation/AVFoundation.h>       //攝像頭麥克風 必須
#import <AssetsLibrary/AssetsLibrary.h>     //相冊權限
#import <CoreLocation/CoreLocation.h>       //位置權限
#import <AddressBook/AddressBook.h>         //通訊錄權限

#import "AppDelegate.h"

#define kAPPName [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]

@implementation LYAuthorizedMaster

#pragma mark -
+(BOOL)checkAuthority:(AVAuthorizationStatus)_status{
    return (_status == AVAuthorizationStatusAuthorized) || (_status == AVAuthorizationStatusNotDetermined);
}
+(void)showAlertController:(AuthorizedFinishBlock)_block device:(NSString *)_device{
    UIAlertController *_alertC = [UIAlertController alertControllerWithTitle:@"沒有權限" message:[NSString stringWithFormat:@"請開啟‘%@’對 %@ 的使用權限",kAPPName,_device] preferredStyle:UIAlertControllerStyleAlert];
    [_alertC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
    [_alertC addAction:[UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    }]];
    [((AppDelegate *)[UIApplication sharedApplication].delegate).window.rootViewController presentViewController:_alertC animated:YES completion:_block];
}

#pragma mark - 攝像頭權限
+(BOOL)checkCameraAuthority{
    return [self checkAuthority:[AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]];
}
+(void)cameraAuthorityCheckSuccess:(AuthorizedFinishBlock)_success fail:(AuthorizedFinishBlock)_fail;{
    if ([self checkCameraAuthority]) {
        if (_success) {
            _success();
        }
    }else{
        [self showAlertController:_fail device:@"相機"];
    }
}

#pragma mark - 麥克風權限
+(BOOL)checkAudioAuthority{
    return [self checkAuthority:[AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]];
}
+(void)audioAuthorityCheckSuccess:(AuthorizedFinishBlock)_success fail:(AuthorizedFinishBlock)_fail{
    if ([self checkAudioAuthority]) {
        if (_success) {
            _success();
        }
    }else{
        [self showAlertController:_fail device:@"麥克風"];
    }
}

#pragma mark - 相冊權限
+(BOOL)checkAlbumAuthority{
    return [ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusAuthorized;
}
+(void)albumAuthorityCheckSuccess:(AuthorizedFinishBlock)_success fail:(AuthorizedFinishBlock)_fail;
{
    if ([self checkAlbumAuthority]) {
        if (_success) {
            _success();
        }
    }else{
        [self showAlertController:_fail device:@"照片"];
    }
}

#pragma mark - 位置權限
+(BOOL)checkLocationAuthority {
    return [CLLocationManager locationServicesEnabled];
}
+(void)locationAuthorityCheckSuccess:(AuthorizedFinishBlock)_success fail:(AuthorizedFinishBlock)_fail{
    
    if ([self checkLocationAuthority]) {
        if (_success) {
            _success();
        }
    }else{
        [self showAlertController:_fail device:@"位置"];
    }
}

#pragma mark - 推送通知權限
+(BOOL)checkPushNotificationAuthority {
    return [[UIApplication sharedApplication] currentUserNotificationSettings].types != UIUserNotificationTypeNone;
}
+(void)pushNotificationAuthorityCheckSuccess:(AuthorizedFinishBlock)_success fail:(AuthorizedFinishBlock)_fail{
    
    if ([self checkAlbumAuthority]) {
        if (_success) {
            _success();
        }
    }else{
        [self showAlertController:_fail device:@"通知"];
    }
}

#pragma mark - 通訊錄權限
+(BOOL)checkAddressBookAuthority {
    return ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized || ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined;
}
+(void)AddressBookAuthorityCheckSuccess:(AuthorizedFinishBlock)_success fail:(AuthorizedFinishBlock)_fail{
    
    if ([self checkAddressBookAuthority]) {
        if (_success) {
            _success();
        }
    }else{
        [self showAlertController:_fail device:@"通訊錄"];
    }
}

最后有些時會遇到不彈出權限提示,或需要在提示框增加詳細描述的時候,需要手動在info.plist加一些字段。

NSLocationWhenInUseUsageDescription    位置權限 使用期間 狀態(tài)

NSLocationAlwaysUsageDescription    位置權限 始終 狀態(tài)

下面這些我并沒有都試,所以也不知道是否正確....

NSLocationUsageDescription    用于訪問位置權限

NSCalendarsUsageDescription    用于訪問日歷權限

NSContactsUsageDescription    用于訪問聯(lián)絡人

NSPhotoLibraryUsageDescription    用于訪問相冊

NSRemindersUsageDescription    用于訪問提醒

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

新聞名稱:iOS應用部分權限控制-創(chuàng)新互聯(lián)
分享鏈接:http://www.chinadenli.net/article10/pshdo.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化品牌網站設計營銷型網站建設電子商務網站導航做網站

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網站網頁設計