ios - 无法使用类型的参数列表调用 'requestAuthorizationToShareTypes'

标签 ios swift swift2 xcode7 healthkit

它说:

Cannot invoke 'requestAuthorizationToShareTypes' with an argument list of type (HKQuantityType, readTypes: HKCharacteristicType, completion: (Bool, NSError!) -> Void)

请帮忙

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    if HKHealthStore.isHealthDataAvailable() {
        let healthStore = HKHealthStore()
        healthStore.requestAuthorizationToShareTypes(HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount)!, readTypes: (HKCharacteristicType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierBiologicalSex))! , completion:{
            (success:Bool,error:NSError!) -> Void in
            if !success{
                print("error")
            }
        })
    }

}

最佳答案

requestAuthorizationForTypes 方法需要Sets HKObjectType。试试这个:

let shareTypes : Set = [HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount)!]
let readTypes : Set = [HKCharacteristicType.characteristicTypeForIdentifier(HKCharacteristicTypeIdentifierBiologicalSex)!]
healthStore.requestAuthorizationToShareTypes(shareTypes, readTypes:readTypes, completion: { (success, error) -> Void in
    if !success{
        print("error")
    }
})

关于ios - 无法使用类型的参数列表调用 'requestAuthorizationToShareTypes',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31836412/

相关文章:

ios - iPad Retina 图像不显示?

ios - 通过长按手势交换 UICollectionViewCells 位置

android - Admob 原生高级广告尺寸

swift - 将函数映射到全局变量中快速错误 "Initializer ' init(_ : )' requires that ' [_ ]' conform to ' LosslessStringConvertible'"

swift - 在 Value 是 Array<SomeProtocol> 的情况下扩展 SignalProducerType

ios - 如何通过合并来自前后摄像头的视频来解决我的方向问题

ios - 当用户从 Cordova 的 iOS 通知中心选择通知时更改状态

android - 使用 Intel XDK 和 Cordova CLI : What is better? 的经验

swift - 自定义凭证提供程序问题 - Swift2.2、AWS 2.4.9、AWSCredentials AWSCredentialsProvider

swift2 - GameCenter 无法工作,身份验证和排行榜未显示