![](/img/trans.png)
[英]How to detect if user tap on “Don't Allow” on Apple's push notification confirmation alert
[英]How to detect if the user doesn't allow Apple Health Kit Authorisation?
我在我的应用程序中使用AppleHealthKit 。 一切都正常。 问题是我无法检测用户在请求许可时是否点击“不允许”按钮。
使用此方法,我的应用程序使用HealthKit ,即使用户不允许这样做。
requestAuthorizationToShareTypes(healthKitTypesToWrite, readTypes: healthKitTypesToRead) { (success, error) -> Void in
if( completion != nil ) {
completion(success:success,error:error)
}
Apple文档:
所以基本上我的问题是如何检测到这一点?
您无法通过设计检测到它:
为了帮助防止敏感健康信息可能泄漏,您的应用无法确定用户是否已授予读取数据的权限。 如果您未获得许可,则看起来好像HealthKit商店中没有所请求类型的数据。
(来自HKHealthStore )
你可以这样做但只针对一种特定的类型而且只针对写入数据(如果你必须检查它们,你也可以对其他类型做同样的事情)
HKHealthStore *_healthStore;
HKQuantityType *stepsType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount];
HKAuthorizationStatus status = [_healthStore authorizationStatusForType:stepsType];
BOOL isActive;
switch (status) {
case HKAuthorizationStatusSharingAuthorized:
isActive = YES;
break;
case HKAuthorizationStatusSharingDenied:
isActive = NO;
break;
case HKAuthorizationStatusNotDetermined:
isActive = NO;
break;
default:
break;
}
NSLog(@"STATUS-------%@", isActive ? @"yes" : @"no");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.