2016-04-06 12 views
-1

Sağlık kitinde kan basıncı verisi kaydedilir.iOS'ta sağlık kiti uygulamasında kan basıncı verilerini nasıl kaydedersiniz

- (void)viewDidLoad { 
    Systolic = 120; 
    Diastolic = 90; 

    [[GSHealthKitManager sharedManager]saveBloodPressureIntoHealthStore:Systolic Dysbp:Diastolic]; 
} 

- (void)saveBloodPressureIntoHealthStore:(double)Systolic Dysbp: (double)Diastolic { 

    HKUnit *BloodPressureUnit = [HKUnit millimeterOfMercuryUnit]; 
    HKQuantity *SystolicQuantity = [HKQuantity quantityWithUnit:BloodPressureUnit doubleValue:Systolic]; 
    HKQuantity *DiastolicQuantity = [HKQuantity quantityWithUnit:BloodPressureUnit doubleValue:Diastolic]; 

    HKQuantityType *SystolicType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodPressureSystolic]; 

    HKQuantityType *DiastolicType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierBloodPressureDiastolic]; 

    NSDate *now = [NSDate date]; 
    HKQuantitySample *SystolicSample = [HKQuantitySample quantitySampleWithType:SystolicType quantity:SystolicQuantity startDate:now endDate:now]; 

    HKQuantitySample *DiastolicSample = [HKQuantitySample quantitySampleWithType:DiastolicType quantity:DiastolicQuantity startDate:now endDate:now]; 

    NSSet *objects=[NSSet setWithObjects:SystolicSample,DiastolicSample, nil]; 

    HKCorrelationType *bloodPressureType = [HKObjectType correlationTypeForIdentifier:HKCorrelationTypeIdentifierBloodPressure]; 

    HKCorrelation *BloodPressure = [HKCorrelation correlationWithType:bloodPressureType startDate:now endDate:now objects:objects]; 

    [self.healthStore saveObject:BloodPressure withCompletion:^(BOOL success, NSError *error) { 
    if (!success) { 
     NSLog(@"An error occured saving the height sample %@. In your app, try to handle this gracefully. The error was: %@.", BloodPressure, error); 
     abort(); 
    } 

    UIAlertView *savealert=[[UIAlertView alloc]initWithTitle:@"HealthDemo" message:@"Blood Pressure values has been saved to Health App" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 

    [savealert show]; 
    }]; 

} 

Uygulamamı çalıştırırsam, abort(); fonksiyon

An error occurred saving the height sample <HKCorrelation> 2016-04-06 14:42:47 +0530 2016-04-06 14:42:47 +0530 (2 objects). In your app, try to handle this gracefully. The error was: Error Domain=com.apple.healthkit Code=5 "Authorization is not determined" UserInfo={NSLocalizedDescription=Authorization is not determined}. 
+0

Eğer HealthKit kullanıcıdan çok erişmek için yetki istedi mi? – Larme

+0

@Larme Cevabınız için teşekkür ederiz. anlamıyorum kardeşim ne anlama geliyor .. aslında sağlık kiti uygulamasında ben gösteride kan basıncını etkinleştirebilirim Kontrol Paneli – satya

+0

Farklı iOS çerçevelerini kullanırken kullanabilmek için kullanıcıdan izin alması oldukça yaygın. HealthKit hakkında bir şey okumadım, ama eminim bunlar bunu kapsamaktadır. HealtKit hakkında birşeyler okumak zorunda mısınız? Kodu aldığınızdan hayır diyorum (http://stackoverflow.com/questions/25642949/for-ios-healthkit-how-to-save-systolic-and-diastolic-blood-pressure-values) ve herhangi bir şey okumadan dümdüz dümdüz, ben bahse girerim ... – trojanfoe

cevap

2

Önce kullanıcıdan izin talep etmelidir:

HKQuantityType* t1 = [HKQuantityType quantityTypeForIdentifier: HKQuantityTypeIdentifierBloodPressureSystolic], 
    t2 = [HKQuantityType quantityTypeForIdentifier: HKQuantityTypeIdentifierBloodPressureDiastolic]; 

    NSSet * requestedTypesSet = [[NSSet alloc] initWithObjects: t1, t2, nil]; 

    [self.healthStore requestAuthorizationToShareTypes: requestedTypesSet readTypes:requestedTypesSet completion:^(BOOL success, NSError *error) { 
     //user response processing goes here, i.e. 
      if(success) { 
       dispatch_async(dispatch_get_main_queue(), ^{ 
        [self saveBloodPressureIntoHealthStore:Systolic Dysbp:Diastolic]; 
       } 
      } 
     }]; 
+0

Cevabınız için teşekkürler .. bana tam kodu verir misiniz .. aslında bu konu bugün sabah ileride vurdu .. bu yüzden bana tam kodu vermek plz .. kodumu değiştirmek için .. plz bana fikir ver .. – satya

+0

ya o iyi çalışıyor. ama değerleri geçmek istiyorum .. sistolik ve diyastolik değerleri .. nasıl değerleri aktarabilirim plz bana – satya

+0

cevabını bildirir misiniz lütfen .. kafamı karıştırdım – satya

İlgili konular