|
|
@@ -0,0 +1,66 @@ |
|
|
import UIKit |
|
|
import ResearchKit |
|
|
|
|
|
|
|
|
class DemoView: UIView { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
class DemoStepViewController : ORKActiveStepViewController { |
|
|
override func viewDidLoad() { |
|
|
super.viewDidLoad() |
|
|
self.view.backgroundColor = UIColor(red:0.0, green:1.0, blue:0.0, alpha:1.0) |
|
|
|
|
|
let demoView = DemoView() |
|
|
demoView.setTranslatesAutoresizingMaskIntoConstraints(false) |
|
|
demoView.backgroundColor = UIColor(red:1.0, green:0.0, blue:0.0, alpha:1.0) |
|
|
self.customView = demoView |
|
|
self.customView?.superview!.setTranslatesAutoresizingMaskIntoConstraints(false) |
|
|
|
|
|
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-[demoView]-|", options: NSLayoutFormatOptions(0), metrics: nil, views: ["demoView": demoView])) |
|
|
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-[demoView]-|", options: NSLayoutFormatOptions(0), metrics: nil, views: ["demoView": demoView])) |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
class DemoStep : ORKActiveStep { |
|
|
static func stepViewControllerClass() -> DemoStepViewController.Type { |
|
|
return DemoStepViewController.self |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@UIApplicationMain |
|
|
class AppDelegate: UIResponder, UIApplicationDelegate { |
|
|
|
|
|
var window: UIWindow? |
|
|
|
|
|
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { |
|
|
let activeStep = DemoStep(identifier: "ds_id") |
|
|
activeStep.title = "Demo Step" |
|
|
var endStep = ORKCompletionStep(identifier: "es_id") |
|
|
endStep.title = "Well done" |
|
|
endStep.text = "thank you" |
|
|
|
|
|
let task = ORKOrderedTask(identifier: "ts_id", steps: [activeStep,endStep]) |
|
|
let taskViewController = ORKTaskViewController(task: task, taskRunUUID: nil) |
|
|
taskViewController.delegate = self |
|
|
taskViewController.outputDirectory = NSURL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! String, isDirectory: true) |
|
|
|
|
|
window?.rootViewController = taskViewController |
|
|
|
|
|
return true |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
extension AppDelegate : ORKTaskViewControllerDelegate { |
|
|
|
|
|
func taskViewController(taskViewController: ORKTaskViewController, didFinishWithReason reason: ORKTaskViewControllerFinishReason, error: NSError?) { |
|
|
//Handle results with taskViewController.result |
|
|
taskViewController.dismissViewControllerAnimated(true, completion: nil) |
|
|
} |
|
|
|
|
|
} |