@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