|
|
|
@ -22,7 +22,7 @@
@@ -22,7 +22,7 @@
|
|
|
|
|
@import CoreLocation; |
|
|
|
|
@import MediaPlayer; |
|
|
|
|
@import Speech;//Xcode 8.0 or later |
|
|
|
|
@import HealthKit; |
|
|
|
|
//@import HealthKit; |
|
|
|
|
@import Intents; |
|
|
|
|
@import CoreBluetooth; |
|
|
|
|
|
|
|
|
@ -30,102 +30,102 @@
@@ -30,102 +30,102 @@
|
|
|
|
|
#define IOS9 ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 9.0) |
|
|
|
|
#define IOS10 ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 10.0) |
|
|
|
|
|
|
|
|
|
@interface JLAuthorizationHealthManager : NSObject |
|
|
|
|
//@interface JLAuthorizationHealthManager : NSObject |
|
|
|
|
|
|
|
|
|
- (void)JL_requestHealthAuthorizationWithShareTypes:(nullable NSSet<HKSampleType *> *)typesToShare |
|
|
|
|
readTypes:(nullable NSSet<HKObjectType *> *)typesToRead |
|
|
|
|
authorizedHandler:(void(^)())authorizedHandler |
|
|
|
|
unAuthorizedHandler:(void(^)())unAuthorizedHandler; |
|
|
|
|
@end |
|
|
|
|
|
|
|
|
|
@implementation JLAuthorizationHealthManager |
|
|
|
|
|
|
|
|
|
- (void)JL_requestHealthAuthorizationWithShareTypes:(nullable NSSet<HKSampleType *> *)typesToShare |
|
|
|
|
readTypes:(nullable NSSet<HKObjectType *> *)typesToRead |
|
|
|
|
authorizedHandler:(void(^)())authorizedHandler |
|
|
|
|
unAuthorizedHandler:(void(^)())unAuthorizedHandler{ |
|
|
|
|
//- (void)JL_requestHealthAuthorizationWithShareTypes:(nullable NSSet<HKSampleType *> *)typesToShare |
|
|
|
|
// readTypes:(nullable NSSet<HKObjectType *> *)typesToRead |
|
|
|
|
// authorizedHandler:(void(^)())authorizedHandler |
|
|
|
|
// unAuthorizedHandler:(void(^)())unAuthorizedHandler; |
|
|
|
|
//@end |
|
|
|
|
// |
|
|
|
|
//@implementation JLAuthorizationHealthManager |
|
|
|
|
|
|
|
|
|
HKHealthStore *healthStore = [[HKHealthStore alloc] init]; |
|
|
|
|
__block BOOL shouldRequestAccess = NO; |
|
|
|
|
if (typesToShare.count > 0) { |
|
|
|
|
|
|
|
|
|
[typesToShare enumerateObjectsUsingBlock:^(HKObjectType * _Nonnull type, BOOL * _Nonnull stop) { |
|
|
|
|
HKAuthorizationStatus authStatus = [healthStore authorizationStatusForType:type]; |
|
|
|
|
if (authStatus == HKAuthorizationStatusNotDetermined) { |
|
|
|
|
shouldRequestAccess = YES; |
|
|
|
|
*stop = YES; |
|
|
|
|
} |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
if (typesToRead.count > 0) { |
|
|
|
|
|
|
|
|
|
[typesToRead enumerateObjectsUsingBlock:^(HKObjectType * _Nonnull type, BOOL * _Nonnull stop) { |
|
|
|
|
HKAuthorizationStatus authStatus = [healthStore authorizationStatusForType:type]; |
|
|
|
|
if (authStatus == HKAuthorizationStatusNotDetermined) { |
|
|
|
|
shouldRequestAccess = YES; |
|
|
|
|
*stop = YES; |
|
|
|
|
} |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
NSAssert(!(typesToRead.count > 0), @"待请求的权限类型数组不能为空"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (shouldRequestAccess) { |
|
|
|
|
[healthStore requestAuthorizationToShareTypes:typesToShare readTypes:typesToRead completion:^(BOOL success, NSError * _Nullable error) { |
|
|
|
|
if (success) { |
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{ |
|
|
|
|
authorizedHandler ? authorizedHandler() : nil; |
|
|
|
|
}); |
|
|
|
|
}else{ |
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{ |
|
|
|
|
unAuthorizedHandler ? unAuthorizedHandler() : nil; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}]; |
|
|
|
|
}else{ |
|
|
|
|
__block BOOL isAuthorized = NO; |
|
|
|
|
if (typesToShare.count > 0) { |
|
|
|
|
[typesToShare enumerateObjectsUsingBlock:^(HKSampleType * _Nonnull type, BOOL * _Nonnull stop) { |
|
|
|
|
HKAuthorizationStatus authStatus = [healthStore authorizationStatusForType:type]; |
|
|
|
|
if (authStatus == HKAuthorizationStatusNotDetermined |
|
|
|
|
|| authStatus == HKAuthorizationStatusSharingDenied) { |
|
|
|
|
isAuthorized = NO; |
|
|
|
|
}else{ |
|
|
|
|
isAuthorized = YES; |
|
|
|
|
} |
|
|
|
|
}]; |
|
|
|
|
}else{ |
|
|
|
|
if (typesToRead.count > 0) { |
|
|
|
|
|
|
|
|
|
[typesToRead enumerateObjectsUsingBlock:^(HKObjectType * _Nonnull type, BOOL * _Nonnull stop) { |
|
|
|
|
HKAuthorizationStatus authStatus = [healthStore authorizationStatusForType:type]; |
|
|
|
|
if (authStatus == HKAuthorizationStatusNotDetermined |
|
|
|
|
|| authStatus == HKAuthorizationStatusSharingDenied) { |
|
|
|
|
isAuthorized = NO; |
|
|
|
|
}else{ |
|
|
|
|
isAuthorized = YES; |
|
|
|
|
} |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
|
NSAssert(!(typesToRead.count > 0), @"待请求的权限类型数组不能为空"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isAuthorized) { |
|
|
|
|
authorizedHandler ? authorizedHandler() : nil; |
|
|
|
|
}else{ |
|
|
|
|
unAuthorizedHandler ? unAuthorizedHandler() : nil; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
@end |
|
|
|
|
//- (void)JL_requestHealthAuthorizationWithShareTypes:(nullable NSSet<HKSampleType *> *)typesToShare |
|
|
|
|
// readTypes:(nullable NSSet<HKObjectType *> *)typesToRead |
|
|
|
|
// authorizedHandler:(void(^)())authorizedHandler |
|
|
|
|
// unAuthorizedHandler:(void(^)())unAuthorizedHandler{ |
|
|
|
|
// |
|
|
|
|
// HKHealthStore *healthStore = [[HKHealthStore alloc] init]; |
|
|
|
|
// __block BOOL shouldRequestAccess = NO; |
|
|
|
|
// if (typesToShare.count > 0) { |
|
|
|
|
// |
|
|
|
|
// [typesToShare enumerateObjectsUsingBlock:^(HKObjectType * _Nonnull type, BOOL * _Nonnull stop) { |
|
|
|
|
// HKAuthorizationStatus authStatus = [healthStore authorizationStatusForType:type]; |
|
|
|
|
// if (authStatus == HKAuthorizationStatusNotDetermined) { |
|
|
|
|
// shouldRequestAccess = YES; |
|
|
|
|
// *stop = YES; |
|
|
|
|
// } |
|
|
|
|
// }]; |
|
|
|
|
// |
|
|
|
|
// }else{ |
|
|
|
|
// if (typesToRead.count > 0) { |
|
|
|
|
// |
|
|
|
|
// [typesToRead enumerateObjectsUsingBlock:^(HKObjectType * _Nonnull type, BOOL * _Nonnull stop) { |
|
|
|
|
// HKAuthorizationStatus authStatus = [healthStore authorizationStatusForType:type]; |
|
|
|
|
// if (authStatus == HKAuthorizationStatusNotDetermined) { |
|
|
|
|
// shouldRequestAccess = YES; |
|
|
|
|
// *stop = YES; |
|
|
|
|
// } |
|
|
|
|
// }]; |
|
|
|
|
// |
|
|
|
|
// |
|
|
|
|
// }else{ |
|
|
|
|
// NSAssert(!(typesToRead.count > 0), @"待请求的权限类型数组不能为空"); |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// if (shouldRequestAccess) { |
|
|
|
|
// [healthStore requestAuthorizationToShareTypes:typesToShare readTypes:typesToRead completion:^(BOOL success, NSError * _Nullable error) { |
|
|
|
|
// if (success) { |
|
|
|
|
// dispatch_async(dispatch_get_main_queue(), ^{ |
|
|
|
|
// authorizedHandler ? authorizedHandler() : nil; |
|
|
|
|
// }); |
|
|
|
|
// }else{ |
|
|
|
|
// dispatch_async(dispatch_get_main_queue(), ^{ |
|
|
|
|
// unAuthorizedHandler ? unAuthorizedHandler() : nil; |
|
|
|
|
// }); |
|
|
|
|
// } |
|
|
|
|
// }]; |
|
|
|
|
// }else{ |
|
|
|
|
// __block BOOL isAuthorized = NO; |
|
|
|
|
// if (typesToShare.count > 0) { |
|
|
|
|
// [typesToShare enumerateObjectsUsingBlock:^(HKSampleType * _Nonnull type, BOOL * _Nonnull stop) { |
|
|
|
|
// HKAuthorizationStatus authStatus = [healthStore authorizationStatusForType:type]; |
|
|
|
|
// if (authStatus == HKAuthorizationStatusNotDetermined |
|
|
|
|
// || authStatus == HKAuthorizationStatusSharingDenied) { |
|
|
|
|
// isAuthorized = NO; |
|
|
|
|
// }else{ |
|
|
|
|
// isAuthorized = YES; |
|
|
|
|
// } |
|
|
|
|
// }]; |
|
|
|
|
// }else{ |
|
|
|
|
// if (typesToRead.count > 0) { |
|
|
|
|
// |
|
|
|
|
// [typesToRead enumerateObjectsUsingBlock:^(HKObjectType * _Nonnull type, BOOL * _Nonnull stop) { |
|
|
|
|
// HKAuthorizationStatus authStatus = [healthStore authorizationStatusForType:type]; |
|
|
|
|
// if (authStatus == HKAuthorizationStatusNotDetermined |
|
|
|
|
// || authStatus == HKAuthorizationStatusSharingDenied) { |
|
|
|
|
// isAuthorized = NO; |
|
|
|
|
// }else{ |
|
|
|
|
// isAuthorized = YES; |
|
|
|
|
// } |
|
|
|
|
// }]; |
|
|
|
|
// |
|
|
|
|
// }else{ |
|
|
|
|
// NSAssert(!(typesToRead.count > 0), @"待请求的权限类型数组不能为空"); |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// if (isAuthorized) { |
|
|
|
|
// authorizedHandler ? authorizedHandler() : nil; |
|
|
|
|
// }else{ |
|
|
|
|
// unAuthorizedHandler ? unAuthorizedHandler() : nil; |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
// } |
|
|
|
|
// |
|
|
|
|
//} |
|
|
|
|
//@end |
|
|
|
|
|
|
|
|
|
@interface JLAuthorizationManager ()<CLLocationManagerDelegate> |
|
|
|
|
|
|
|
|
@ -226,19 +226,19 @@
@@ -226,19 +226,19 @@
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (void)JL_requestHealthAuthorizationWithShareTypes:(NSSet*)typesToShare |
|
|
|
|
readTypes:(NSSet*)typesToRead |
|
|
|
|
authorizedHandler:(void(^)())authorizedHandler |
|
|
|
|
unAuthorizedHandler:(void(^)())unAuthorizedHandler{ |
|
|
|
|
|
|
|
|
|
JLAuthorizationHealthManager *healthManager = [JLAuthorizationHealthManager new]; |
|
|
|
|
[healthManager JL_requestHealthAuthorizationWithShareTypes:typesToShare |
|
|
|
|
readTypes:typesToRead |
|
|
|
|
authorizedHandler:authorizedHandler |
|
|
|
|
unAuthorizedHandler:unAuthorizedHandler]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
//- (void)JL_requestHealthAuthorizationWithShareTypes:(NSSet*)typesToShare |
|
|
|
|
// readTypes:(NSSet*)typesToRead |
|
|
|
|
// authorizedHandler:(void(^)())authorizedHandler |
|
|
|
|
// unAuthorizedHandler:(void(^)())unAuthorizedHandler{ |
|
|
|
|
// |
|
|
|
|
// JLAuthorizationHealthManager *healthManager = [JLAuthorizationHealthManager new]; |
|
|
|
|
// [healthManager JL_requestHealthAuthorizationWithShareTypes:typesToShare |
|
|
|
|
// readTypes:typesToRead |
|
|
|
|
// authorizedHandler:authorizedHandler |
|
|
|
|
// unAuthorizedHandler:unAuthorizedHandler]; |
|
|
|
|
// |
|
|
|
|
// |
|
|
|
|
//} |
|
|
|
|
|
|
|
|
|
#pragma mark - Photo Library |
|
|
|
|
- (void)p_requestPhotoLibraryAccessWithAuthorizedHandler:(void(^)())authorizedHandler |
|
|
|
|