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

    xiaoxiao2021-04-14  52

    @implementation OTUniversalMethod (VisitDevice)

    - (BOOL)isAvailablyForAlbum {

        ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];

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

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

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

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

            alert.delegate = self;

            alert.tag = HOS_ALERT_TAG_ALBUM;

            [alert show];

            return NO;

        }

        return YES;

    }

    - (BOOL)isAvailablyForCamera {

        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];

        if(authStatus  == AVAuthorizationStatusRestricted ||

           authStatus == AVAuthorizationStatusDenied ) {

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

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

            alterView.delegate = self;

            alterView.tag = HOS_ALERT_TAG_CAMERA;

            [alterView show];

            return NO;

        }

        return YES;

    }

    - (BOOL)isAvailablyForAddressBook {

        

        ABAuthorizationStatus authStatus = ABAddressBookGetAuthorizationStatus();

        if(authStatus == kABAuthorizationStatusRestricted || authStatus ==

           kABAuthorizationStatusDenied){

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

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

            alterView.delegate = self;

            alterView.tag = HOS_ALERT_TAG_ADDRESSBOOK;

            [alterView show];

            return NO;

        }

        return YES;

    }

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

        if (alertView.tag == HOS_ALERT_TAG_ALBUM) {

            if (buttonIndex == 1) {

                if(IOS8_And_Later){

                    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]) {

                        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

                    }

                }

                

            }

        }

        

        if (alertView.tag == HOS_ALERT_TAG_CAMERA) {

            if (buttonIndex == 1) {

                if(IOS8_And_Later){

                    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]) {

                        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

                    }

                }

            }

        }

        

        if (alertView.tag == HOS_ALERT_TAG_ADDRESSBOOK) {

            if (buttonIndex == 1) {

                if(IOS8_And_Later){

                    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]) {

                        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

                    }

                }

            }

        }

    }

    @end

    转载请注明原文地址: https://ju.6miu.com/read-669545.html

    最新回复(0)