ios - Swift: 'Authorization to share the following types is disallowed: HKQuantityTypeIdentifierAppleExerciseTime' -
i trying use healthkit following tutorial (https://www.raywenderlich.com/86336/ios-8-healthkit-swift-getting-started) requiring different hkquantitytypeidentifier. code in healthkitmanager class:
import foundation import uikit import healthkit class healthkitmanager { let healthkitstore:hkhealthstore = hkhealthstore() func authorizehealthkit(completion: ((_ success:bool, _ error:nserror?) -> void)!) { let healthkittypestowrite: set<hksampletype> = [ hkobjecttype.quantitytype(foridentifier: hkquantitytypeidentifier.appleexercisetime)! ] let healthkittypestoread: set<hkobjecttype> = [ hkobjecttype.quantitytype(foridentifier: hkquantitytypeidentifier.appleexercisetime)! ] // if store not available (for instance, ipad) return error , don't go on. if !hkhealthstore.ishealthdataavailable() { let error = nserror(domain: "com.example", code: 2, userinfo: [nslocalizeddescriptionkey:"healthkit not available in device"]) if( completion != nil ) { completion?(false, error) } return; } healthkitstore.requestauthorization(toshare: healthkittypestowrite, read: healthkittypestoread) { (success, error) -> void in completion?(success, error! nserror) } }
}
and in viewcontroller trying call healthkit:
let healthmanager:healthkitmanager = healthkitmanager() func authorizehealthkit() { print("1") healthmanager.authorizehealthkit { (authorized, error) -> void in if authorized { print("healthkit authorization received.") } else { print("healthkit authorization denied!") if error != nil { print("\(error)") } } } }
however when calling authorizehealthkit getting error: 'nsinvalidargumentexception', reason: 'authorization share following types disallowed: hkquantitytypeidentifierappleexercisetime'. print "1" statement called before crash.
your app not allowed request authorization write hkquantitytypeidentifier.appleexercisetime
since definition of type proprietary apple. should remove hkquantitytype
healthkittypestowrite
.
Comments
Post a Comment