2016-09-09 2 views
0

Есть ли способ отправить XML-файл (CDA) в приложение работоспособности из другого приложения? Поскольку мое приложение получает XML-файл из источника, и я хочу отправить его непосредственно в новое приложение для здоровья (iOS 10).SWIFT: CDA to iOS 10 Приложение для здоровья

ответ

0

Создайте HKCDADocumentSample и сохраните его с помощью HKHealthStore.

+0

Вы знаете, как мне получить доступ и отобразить все доступные медицинские записи, хранящиеся в healthkit? – srbalan

0

Во-первых, проверьте разрешения

(void) checkForAuthorization { 
    if ([HKHealthStore isHealthDataAvailable]) { 
    NSSet *setRead = [NSSet setWithObjects [HKObjectTypedocumentTypeForIdentifier:HKDocumentTypeIdentifierCDA], nil]; 
    NSSet *setWrite = [NSSet setWithObjects:[HKObjectType documentTypeForIdentifier:HKDocumentTypeIdentifierCDA], nil]; 
    [_store requestAuthorizationToShareTypes:setWrite readTypes:nil completion:^(BOOL success, NSError * _Nullable error) { 
    if (error) { 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; 
      [alert show]; 
    } else if (success) { 
      [self performSelectorOnMainThread:@selector(addDocumentToHealthApp) withObject:nil waitUntilDone:NO]; 
    } 
     NSLog(@" Success = %@",success? @"YES" : @"NO"); 
    } ]; 
    } else { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Health Kit not supported in device." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; 
    [alert show]; 
    } 

}

Во-вторых, добавить запись wmthod это добавит запись здоровья для приложения здоровья.

(void) addRecordToHealthApp 
{ 

NSURL *cdaPath = [[NSBundle mainBundle] URLForResource:@"sample" withExtension:@"xml"]; 

NSString*stringPath = [cdaPath absoluteString]; 
    NSData *dataOfCDAFile = [NSData dataWithContentsOfURL:[NSURL URLWithString:stringPath]]; 

NSDate *now = [NSDate date]; 
int daysToAdd = 7; 
NSDate *newDate1 = [now dateByAddingTimeInterval:60*60*24*daysToAdd]; 

NSError *err; 
HKCDADocumentSample *doc = [HKCDADocumentSample CDADocumentSampleWithData:dataOfCDAFile startDate:[NSDate date] endDate:newDate1 metadata:nil validationError:&err ]; 

UIAlertView *alert; 
if (err) { 
    alert = [[UIAlertView alloc] initWithTitle:@"Error" message:err.localizedDescription delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; 
    [alert show]; 
} 





[_store saveObject:doc withCompletion:^(BOOL success, NSError * _Nullable error) { 
    NSLog("Stored %@",[email protected]"YES":@"NO"); 
}]; 

} 
+0

Можете ли вы сделать это быстрым языком? – srbalan

Смежные вопросы