編集:私は最終的にこれを解決しました。これは、キャッシュの問題とコード行の欠落の組み合わせでした。実際にタスクをView Controllerに追加したことはありません。どういうわけか、そのステップを逃しました。しかし、githubデモプロジェクトを実行するだけで奇妙なエラーが発生し、Xcodeを正常に機能させるために、キャッシュディレクトリを再起動してsudoで削除する必要がありました。
Objective-C で Research Kit を実装しようとしています。チュートリアルはなく、参照できるドキュメントはほとんどありません。「視覚的同意ステップに可視シーンがありません」というクラッシュが発生します。ビュー コントローラーが 1 つあり、そのビュー コントローラーに IBAction "consentTapped" をトリガーするボタンがあります。Ray Wenderlich チュートリアルhttp://www.raywenderlich.com/104575/researchkit-tutorial-with-swiftとこの GitHub プロジェクト: https://github.com/weberbry/ResearchKitConsentDemoを適応させようとしました。
これを自分でトラブルシューティングしようとして、すべてのコードをviewDidAppearに入れ、カプセル化されたメソッドから取り出しました。その方法で間違いを犯したと思ったのですが、まだ問題があります:
これが私のコードです:
#import "ViewController.h"
#import <ResearchKit/ResearchKit.h>
@interface ViewController ()<ORKTaskViewControllerDelegate>
@property (strong, nonatomic) ORKConsentDocument *consentDocument;
@property (strong, nonatomic) ORKOrderedTask *orderedTask;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSString *resource = [[NSBundle mainBundle] pathForResource:@"ConsentText" ofType:@"json"];
NSData *consentData = [NSData dataWithContentsOfFile:resource];
NSDictionary *parsedConsentData = [NSJSONSerialization JSONObjectWithData:consentData options:NSJSONReadingMutableContainers error:nil];
NSArray *sectionDataParsedFromInputFile = [parsedConsentData objectForKey:@"sections"];
NSMutableArray *consentSections = [NSMutableArray new];
for (NSDictionary *sectionDictionary in sectionDataParsedFromInputFile) {
ORKConsentSectionType sectionType = [[sectionDictionary objectForKey:@"sectionType"] integerValue];
NSString *title = [sectionDictionary objectForKey:@"sectionTitle"];
NSString *summary = [sectionDictionary objectForKey:@"sectionSummary"];
NSString *detail = [sectionDictionary objectForKey:@"sectionDetail"];
ORKConsentSection *section = [[ORKConsentSection alloc] initWithType:sectionType];
section.title = title;
section.summary = summary;
section.htmlContent = detail;
ORKConsentSection *consentSection = section;
[consentSections addObject:consentSection];
}
ORKConsentSection *introSection = [[ORKConsentSection alloc] initWithType:ORKConsentSectionTypeOnlyInDocument];
introSection.title = @"Intro Language";
introSection.content = @"This will only be shown in the consent document because this sectionType is map to ORKConsentSectionTypeOnlyInDocument. A consent document can include many sections with type ORKConsentSectionTypeOnlyInDocument. In this document there is a ORKConsentSectionTypeOnlyInDocument section as an intro and one as a closing section";
[consentSections insertObject:introSection atIndex:0];
ORKConsentSection *closingSection = [[ORKConsentSection alloc] initWithType:ORKConsentSectionTypeOnlyInDocument];
closingSection.title = @"Additional Terms";
closingSection.htmlContent = @"Adding a ORKConsentSectionTypeOnlyInDocument at the end of a consent can be helpful to include any additional legal or related information.";
[consentSections addObject:closingSection];
self.consentDocument = [ORKConsentDocument new];
self.consentDocument.title = @"Demo Consent";
self.consentDocument.sections = consentSections;
ORKConsentSignature *signature = [ORKConsentSignature new];
self.consentDocument.signatures = [NSArray arrayWithObject:signature];
ORKVisualConsentStep *visualConsentStep = [[ORKVisualConsentStep alloc] initWithIdentifier:@"visualConsentStep" document:self.consentDocument];
ORKConsentReviewStep *consentReviewStep = [[ORKConsentReviewStep alloc] initWithIdentifier:@"consentReviewStep" signature:self.consentDocument.signatures.firstObject inDocument:self.consentDocument];
consentReviewStep.text = @"Review Consent!";
consentReviewStep.reasonForConsent = @"I confirm that I consent to join this study";
self.orderedTask = [[ORKOrderedTask alloc] initWithIdentifier:@"consent" steps:@[visualConsentStep, consentReviewStep]];
}
- (IBAction)consentTapped:(id)sender {
ORKTaskViewController *taskViewController = [[ORKTaskViewController alloc]initWithTask:self.orderedTask taskRunUUID:nil];
taskViewController.delegate = self;
[self presentViewController:taskViewController animated:YES completion:nil];
}
- (void)taskViewController:(ORKTaskViewController *)taskViewController
didFinishWithReason:(ORKTaskViewControllerFinishReason)reason
error:(NSError *)error {
ORKTaskResult *taskResult = [taskViewController result];
[self dismissViewControllerAnimated:YES completion:nil];
}
エラーの文言から、別のビュー コントローラー シーンがあるはずだと思いますが、見逃さない限り、Ray Wenderlich チュートリアルには表示されませんでした。私はまだ迅速にまったく知らないので、知っていて、私が何かを見逃していることに気付いたら、私に知らせてください.
viewDidAppear を離れると、クラッシュが発生します。
また、これは私の最初の投稿なので、コミュニティ ガイドラインに従っていない場合はお知らせください。すぐに投稿を変更します。
編集:これが作業コードです。また、投稿した元のエラーに加えて奇妙なエラーが発生した場合は、DerivedData フォルダーを sudo で削除し、再起動してください。欠落していた行は「taskViewController.task = self.orderedTask;」でした。
#import "ViewController.h"
#import <ResearchKit/ResearchKit.h>
@interface ViewController ()<ORKTaskViewControllerDelegate>
@property (strong, nonatomic) ORKConsentDocument *consentDocument;
@property (strong, nonatomic) ORKOrderedTask *orderedTask;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSString *resource = [[NSBundle mainBundle] pathForResource:@"ConsentText" ofType:@"json"];
NSData *consentData = [NSData dataWithContentsOfFile:resource];
NSDictionary *parsedConsentData = [NSJSONSerialization JSONObjectWithData:consentData options:NSJSONReadingMutableContainers error:nil];
NSArray *sectionDataParsedFromInputFile = [parsedConsentData objectForKey:@"sections"];
NSMutableArray *consentSections = [NSMutableArray new];
for (NSDictionary *sectionDictionary in sectionDataParsedFromInputFile) {
ORKConsentSectionType sectionType = [[sectionDictionary objectForKey:@"sectionType"] integerValue];
NSString *title = [sectionDictionary objectForKey:@"sectionTitle"];
NSString *summary = [sectionDictionary objectForKey:@"sectionSummary"];
NSString *detail = [sectionDictionary objectForKey:@"sectionDetail"];
ORKConsentSection *section = [[ORKConsentSection alloc] initWithType:sectionType];
section.title = title;
section.summary = summary;
section.htmlContent = detail;
ORKConsentSection *consentSection = section;
[consentSections addObject:consentSection];
}
ORKConsentSection *introSection = [[ORKConsentSection alloc] initWithType:ORKConsentSectionTypeOnlyInDocument];
introSection.title = @"Intro Language";
introSection.htmlContent = @"This will only be shown in the consent document because this sectionType is map to ORKConsentSectionTypeOnlyInDocument. A consent document can include many sections with type ORKConsentSectionTypeOnlyInDocument. In this document there is a ORKConsentSectionTypeOnlyInDocument section as an intro and one as a closing section";
[consentSections insertObject:introSection atIndex:0];
ORKConsentSection *closingSection = [[ORKConsentSection alloc] initWithType:ORKConsentSectionTypeOnlyInDocument];
closingSection.title = @"Additional Terms";
closingSection.htmlContent = @"Adding a ORKConsentSectionTypeOnlyInDocument at the end of a consent can be helpful to include any additional legal or related information.";
[consentSections addObject:closingSection];
NSArray *sections = consentSections;
self.consentDocument = [ORKConsentDocument new];
self.consentDocument.title = @"Demo Consent";
self.consentDocument.sections = consentSections;
ORKConsentSignature *signature = [ORKConsentSignature new];
self.consentDocument.signatures = [NSArray arrayWithObject:signature];
ORKVisualConsentStep *visualConsentStep = [[ORKVisualConsentStep alloc] initWithIdentifier:@"visualConsentStep" document:self.consentDocument];
ORKConsentReviewStep *consentReviewStep = [[ORKConsentReviewStep alloc] initWithIdentifier:@"consentReviewStep" signature:self.consentDocument.signatures.firstObject inDocument:self.consentDocument];
consentReviewStep.text = @"Review Consent!";
consentReviewStep.reasonForConsent = @"I confirm that I consent to join this study";
self.orderedTask = [[ORKOrderedTask alloc] initWithIdentifier:@"consent" steps:@[visualConsentStep, consentReviewStep]];
}
- (IBAction)consentTapped:(id)sender {
ORKTaskViewController *taskViewController = [[ORKTaskViewController alloc] init];
taskViewController.task = self.orderedTask;
taskViewController.delegate = self;
[self presentViewController:taskViewController animated:YES completion:nil];
}
- (void)taskViewController:(ORKTaskViewController *)taskViewController
didFinishWithReason:(ORKTaskViewControllerFinishReason)reason
error:(NSError *)error {
ORKTaskResult *taskResult = [taskViewController result];
[self dismissViewControllerAnimated:YES completion:nil];
}