2016-11-24 65 views
4

在我的手錶擴展我調用這個函數:HealthKit權限表中不顯示

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應用程序然後選擇我的應用程序並以這種方式授予權限來授予權限。

我在說的權限表是這個。 enter image description here

編輯︰我從requestAuthorization()方法調用打印此錯誤。

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

一旦你拒絕授權,你只能在設置中打開它。或者重新安裝應用程序。 – Lumialxk

+0

我從來沒有拒絕授權。我試圖重新安裝應用程序,我仍然從未獲得權限表。 – raginggoat

+0

您正在使用哪個iOS版本? – Mehul

回答

0

有了這個TestHealthKit,我能打開健康套件許可表。

 // 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; 
     } 

    } 

此外,請檢查您是否啓用了權利,如圖所示。 entitlements

+0

這正是我所擁有的權利。如果我轉到Apple Health應用程序並從那裏向我的應用程序授予權限,我的應用程序中的所有內容都可以正常工作從字面上看,我遇到的唯一問題是,當手表應用程序請求手機的許可時,沒有看到權限表,當我選擇通過手機上的提示打開應用程序時,它會打開我的應用程序,但我沒有看到權限片。 – raginggoat