相册,相机,通讯录访问权限标准写法

来源:互联网 发布:itunes软件下载 编辑:程序博客网 时间:2024/05/21 18:43

@implementation OTUniversalMethod (VisitDevice)

- (BOOL)isAvailablyForAlbum {

    ALAuthorizationStatus author = [ALAssetsLibraryauthorizationStatus];

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

        NSString *appName = [[[NSBundlemainBundle] infoDictionary]objectForKey:@"CFBundleName"];

        NSString *msg = [NSStringstringWithFormat:@"请在iPhone设置”-“隐私”-“照片选项中,允许%@访问你的照片。",appName];

        UIAlertView * alert = [[UIAlertViewalloc]initWithTitle:@"相册服务未开启"message:msg delegate:nilcancelButtonTitle:@"取消"otherButtonTitles:@"立即开启",nil];

        alert.delegate =self;

        alert.tag =HOS_ALERT_TAG_ALBUM;

        [alert show];

        returnNO;

    }

    returnYES;

}


- (BOOL)isAvailablyForCamera {

    AVAuthorizationStatus authStatus = [AVCaptureDeviceauthorizationStatusForMediaType:AVMediaTypeVideo];

    if(authStatus  ==AVAuthorizationStatusRestricted ||

       authStatus == AVAuthorizationStatusDenied ) {

        NSString* msg = [NSStringstringWithFormat:@"请在设置”-“隐私”-“相机选项中,允许%@访问你的相机。",[[[NSBundlemainBundle] infoDictionary]objectForKey:@"CFBundleName"]];

        UIAlertView *alterView = [[UIAlertViewalloc] initWithTitle:@"相机服务未开启"message:msg delegate:nilcancelButtonTitle:@"取消"otherButtonTitles:@"立即开启",nil];

        alterView.delegate =self;

        alterView.tag =HOS_ALERT_TAG_CAMERA;

        [alterView show];

        returnNO;

    }

    returnYES;

}


- (BOOL)isAvailablyForAddressBook {

    

    ABAuthorizationStatus authStatus =ABAddressBookGetAuthorizationStatus();

    if(authStatus ==kABAuthorizationStatusRestricted || authStatus ==

       kABAuthorizationStatusDenied){

        NSString* msg = [NSStringstringWithFormat:@"请在设置-隐私-通讯录选项中,允许%@访问你的通讯录。",[[[NSBundlemainBundle] infoDictionary]objectForKey:@"CFBundleName"]];

        UIAlertView *alterView = [[UIAlertViewalloc] initWithTitle:@"相机服务未开启"message:msg delegate:nilcancelButtonTitle:@"取消"otherButtonTitles:@"立即开启",nil];

        alterView.delegate =self;

        alterView.tag =HOS_ALERT_TAG_ADDRESSBOOK;

        [alterView show];

        returnNO;

    }

    returnYES;

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

    if (alertView.tag ==HOS_ALERT_TAG_ALBUM) {

        if (buttonIndex ==1) {

            if(IOS8_And_Later){

                if ([[UIApplicationsharedApplication] canOpenURL:[NSURLURLWithString:UIApplicationOpenSettingsURLString]]) {

                    [[UIApplicationsharedApplication] openURL:[NSURLURLWithString:UIApplicationOpenSettingsURLString]];

                }

            }

            

        }

    }

    

    if (alertView.tag ==HOS_ALERT_TAG_CAMERA) {

        if (buttonIndex ==1) {

            if(IOS8_And_Later){

                if ([[UIApplicationsharedApplication] canOpenURL:[NSURLURLWithString:UIApplicationOpenSettingsURLString]]) {

                    [[UIApplicationsharedApplication] openURL:[NSURLURLWithString:UIApplicationOpenSettingsURLString]];

                }

            }

        }

    }

    

    if (alertView.tag ==HOS_ALERT_TAG_ADDRESSBOOK) {

        if (buttonIndex ==1) {

            if(IOS8_And_Later){

                if ([[UIApplicationsharedApplication] canOpenURL:[NSURLURLWithString:UIApplicationOpenSettingsURLString]]) {

                    [[UIApplicationsharedApplication] openURL:[NSURLURLWithString:UIApplicationOpenSettingsURLString]];

                }

            }

        }

    }

}


@end

0 0