【问题标题】:HealthKit Permission Sheet Not AppearingHealthKit 许可表未出现
【发布时间】:2016-11-24 03:06:39
【问题描述】:

在我的手表扩展中,我调用了这个函数:

func requestAuthorization() {
        let healthStore = HKHealthStore()
        let workoutType = HKObjectType.workoutType()
        let heartRateType = HKObjectType.quantityType(forIdentifier: .heartRate)

        //reading
        let readingTypes = Set([heartRateType!, workoutType])

        //writing
        let writingTypes = Set([heartRateType!, workoutType])

        //auth request
        healthStore.requestAuthorization(toShare: writingTypes, read: readingTypes) { (success, error) -> Void in

            if error != nil {
                print("error \(error?.localizedDescription)")
            } else if success {
                self.startButton.setEnabled(true)
            } else if !success {
                self.startButton.setEnabled(false)
            }
        }
    }

在 AppDelegate.swift 中,我有:

func applicationShouldRequestHealthAuthorization(_ application: UIApplication) {
        let healthStore = HKHealthStore()
        healthStore.handleAuthorizationForExtension { (success, error) -> Void in
            //...
        }
    }

我在手表和手机上看到对话框,当我从对话框中告诉它时,它会在手机上打开应用程序。我遇到的问题是电话应用程序没有显示为了允许权限而应该显示的权限表。这里提到了许可表: https://developer.apple.com/reference/healthkit

我需要做些什么才能让它出现以便授予权限?就目前而言,我可以通过转到 Health 应用程序来授予权限,然后获取并选择我的应用程序并以这种方式授予权限。

我说的权限表就是这个。

编辑:我从 requestAuthorization() 方法调用中打印出此错误。

error Optional("Required usage description strings not present in app\'s Info.plist")

【问题讨论】:

  • 一旦你拒绝授权,你只能在设置中打开这个。或者重新安装应用。
  • 我从未拒绝过授权。我尝试重新安装该应用程序,但仍然没有获得许可表。
  • 您使用的是哪个 iOS 版本?
  • @Mehul iOS 10.1.1 和 watchOS 3.1
  • 您设法解决了这个问题吗?我在 10.3b6 / 3.1.3 中看到了同样的情况

标签: ios swift watchkit healthkit


【解决方案1】:

有了这个TestHealthKit,我可以打开health-kit 权限表。

        // 4.  Request HealthKit authorization
    (HealthStore as! HKHealthStore).requestAuthorizationToShareTypes(nil, readTypes: dataTypesToRead()) { (success, error) -> Void in

        //            self.CheckAuthorizationStatusFor(self.dataTypesToRead())
        if (success)
        {

            SuccessCompletion(success: success)
            return;
        }
        else
        {

            FailureCompletion(err: error)
            return;
        }

    }

另外,请检查您是否启用了如图所示的权利。 .

【讨论】:

  • 这正是我所拥有的,并且权利已开启。如果我转到 Apple Health 应用程序并从那里授予对我的应用程序的权限,我的应用程序中的所有内容都可以正常工作。从字面上看,我遇到的唯一问题是当手表应用程序从手机请求权限时看不到权限表,当我选择从手机上的警报中打开应用程序时,它会打开我的应用程序但我看不到权限表。
【解决方案2】:

如文档中所述,如果您的应用使用读取或更新用户健康数据的 API,则必须将必要的密钥添加到 .plist。

NSHealthShareUsageDescription - 向用户发送一条消息,解释应用为何请求从 HealthKit 商店读取样本的权限。

NSHealthUpdateUsageDescription - 向用户发送一条消息,解释应用为何请求将样本保存到 HealthKit 商店的权限。

【讨论】:

    猜你喜欢
    • 2016-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多