-
Notifications
You must be signed in to change notification settings - Fork 3
12.27 #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
12.27 #2
Changes from all commits
d6e5092
0af66e6
95f7f4b
e490e6a
03b32f9
846a5de
b10bf49
64d8bf4
cc34b14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| # ResearchKit 教程 | ||
|
|
||
| 在本教程中,我们将使用 Swift 4 和 XCode 9+ 来解决 Apple 的 ResearchKit 和 Healthkit 的问题。所需要的功能包括创建一个同意书以从用户那里请求批准,分发带有不同类型问题的调查表单,以及 iOS 应用程序从 iPhone 的 Health 应用程序中收集数据的访问点。 | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
|
|
||
| 首先,让我们创建一个标准的 XCode 项目。我们想通过以下步骤将 ResearchKit 和 HealthKit 嵌入到我们的 iOS 应用程序中。 | ||
|
|
||
| 1. 请注册一个开发者帐户(用于 HealthKit 使用),大约需要5-10分钟。[https://developer.apple.com/programs/] 克隆此存储库并按照步骤进行操作!使用 [master] 获取完整的解决方案和 [starterkit] 来填写代码。 | ||
|
|
||
| 2. 我们要下载最新版本的 ResearchKit,并在终端中键入 | ||
|
|
||
| ``` | ||
| git clone -b stable [https://github.com/ResearchKit/ResearchKit.git](https://github.com/ResearchKit/ResearchKit) | ||
| ``` | ||
| 然后,进入带有 `.xcodeprj` 扩展名的文件,并通过运行 ResearchKit 框架来构建项目。 | ||
|
|
||
| 3. 将 **ResearchKit.xcodeproj** 拖到当前 iOS 项目中,如果需要,请复制项目。如果在拖入后看不到 ResearchKit 旁边有箭头,请等待加载,或关闭并重新打开项目。 | ||
|
|
||
|  | ||
|
|
||
| 4. 找到项目的 **General** 设置,并找到 `+Embedded Binaries`。单击 “+” 按钮并添加 ResearchKit。 | ||
|
|
||
|  | ||
|
|
||
| 5. 要使用 HealthKit,请找到 **Capabilities** 设置,滑动到底部以打开 HealthKit 访问,它会自动添加到你的项目中。 | ||
|
|
||
|  | ||
|
|
||
| 6. 在你的 `info.plist` 中,右键单击以打开源代码,然后粘贴: | ||
|
|
||
| ```swift | ||
| <key>NSHealthShareUsageDescription</key> | ||
| <string>Need to share healthkit information</string> | ||
| <key>NSHealthUpdateUsageDescription</key> | ||
| <string>Need healthkit to track steps</string> | ||
| ``` | ||
|
|
||
|  | ||
|
|
||
| 7. (可选)如果你在 XCode 模拟器中测试代码,则必须从 Health App 模拟数据,以便从 HealthStore 获取结果。为此,请运行 iPhone 模拟器,单击硬件选项卡的主页按钮,然后导航到 Health 应用程序。点击要查看的类别,然后使用 “+” 按钮添加数据。例如,如果你要获取步数,那么请找到 **活动**,添加不同天数的运动量。 | ||
|
|
||
| 上面的步骤为你的 Xcode 项目安装了 ResearchKit 和 HealthKit。 | ||
|
|
||
| -------------------------------------------------------------------------------- | ||
|
|
||
| **master** 分支包含具有 ResearchKit 同意和调查表单以及 HealthKit 访问和步数计数的完整代码。**starterkit** 分支包含具有注释和适用于项目各部分的自行添加/自定义的代码部分。 | ||
|
|
||
| **Main.storyboard** 创建导航控制器,将按钮连接到同意、调查和步数计数的特定功能,用于描述用途的文本框以及用于 HealthKit 数据的单独视图控制器。将按钮和文本框对齐以适应每个 iPhone 产品的规格。 | ||
|
|
||
| **FirstViewController.swift** 将同意和调查按钮链接到其特定功能,该功能呈现一个具有特定任务(例如 ConsentTask 和 SurveyTasks)的新 taskViewController。taskViewController 继承自 ORKTaskViewController,用来在操作完成后关闭 viewController。 | ||
|
|
||
| **ConsentDocument.swift** 和 **ConsentTasks.swift** 创建了一个同意书,要求用户同意研究。**ConsentTasks.swift** 创建了一个 ORKOrderedTask 来逐步执行创建的文档。**ConsentDocument.swift** 使用特定问题创建了一个 ORKConsentDocument,用户可以同意,并在表单中包含签名部分。同意事项的示例如下: | ||
|
|
||
| ```Swift | ||
| let consentSectionTypes: [ORKConsentSectionType] = [ | ||
| .overview, | ||
| .dataGathering, | ||
| .privacy, | ||
| .dataUse, | ||
| .studySurvey, | ||
| .studyTasks, | ||
| .withdrawing | ||
| ] | ||
| ``` | ||
|
|
||
| **SurveyTask.swift** 创建了一个供用户填写的简单调查表单。它也是一个 ORKOrderedTask,初始化了问题的格式和详细信息,以及一个用于逐步执行的摘要步骤。示例问题如下: | ||
|
|
||
| ```Swift | ||
| let nameAnswerFormat = ORKTextAnswerFormat(maximumLength: 20) | ||
| nameAnswerFormat.multipleLines = false | ||
| let nameQuestionStepTitle = "What is your name?" | ||
| let nameQuestionStep = ORKQuestionStep(identifier: "QuestionStep", title: nameQuestionStepTitle, answer: nameAnswerFormat) | ||
| steps += [nameQuestionStep] | ||
| ``` | ||
|
|
||
| **HealthKitViewController.swift** 请求 HealthKit 访问并获取用户过去七天的步数。请记住,HealthKit 访问表单将仅出现一次,因为用户只需要接受一次协议。请求信息授权的示例代码如下: | ||
|
|
||
| ```Swift | ||
| if HKHealthStore.isHealthDataAvailable() { | ||
| let stepsCount = NSSet(object: HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.stepCount)) | ||
| let sharedObjects = NSSet(objects: HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.height),HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.bodyMass)) | ||
|
|
||
| healthStore.requestAuthorization(toShare: sharedObjects as? Set<HKSampleType>, read: stepsCount as? Set<HKObjectType>, completion: { (success, err) in | ||
| self.getStepCount(sender: self) | ||
| }) | ||
|
|
||
| } | ||
| ``` | ||
| 创建用于 HealthStor 执行的查询的示例代码如下: | ||
| ```Swift | ||
| let predicate = HKQuery.predicateForSamples(withStart: dates, end: Date(), options: []) | ||
| let query = HKSampleQuery(sampleType: type!, predicate: predicate, limit: 0, sortDescriptors: nil) { | ||
| query, results, error in | ||
| var steps: Double = 0 | ||
| var allSteps = [Double]() | ||
| if let myResults = results { | ||
| for result in myResults as! [HKQuantitySample] { | ||
| print(myResults) | ||
| steps += result.quantity.doubleValue(for: HKUnit.count()) | ||
| allSteps.append(result.quantity.doubleValue(for: HKUnit.count())) | ||
| } | ||
| } | ||
| completion(steps, allSteps, error as NSError?) | ||
|
|
||
| } | ||
|
|
||
| // Executes query through healthstore | ||
| healthStore.execute(query) | ||
| ``` | ||
|
|
||
| 一上就是如何使用 Swift 4 和 XCode 9 来解决 ResearchKit 和 HealthKit 问题的教程。你可以自定义这些项目,并保存信息以在 iOS 应用程序中的其他部分使用,以此来创建一个医疗保健应用。 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,47 +1,36 @@ | ||
| # Web API教程 | ||
| # Web API 教程 | ||
|
|
||
| ### 概述 | ||
| ### 介绍 | ||
|
|
||
| 本研讨会的目标是学习如何使用 Node、MongoDB 和 Express 构建 RESTful Web API。从这个研讨会中,你将了解什么是 Web API,深入了解 Web 的前端/后端结构,并为你的 We b应用程序构建自己的后端!你还将学到一些关于 JavaScript 以及你可以在其中执行的所有有趣的事情。 | ||
| 本教程的目标是讲述如何学习和使用 Node、MongoDB 和 Express 构建 RESTful Web API。在本教程中,你将了解什么是 Web API,深入了解 Web 的前端和后端结构,并为你的 Web 应用程序构建自己的后端!你还将学到一些关于 JavaScript 的知识以及你可以做的所有有趣的事情。 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 加入对 Node、MongoDB 和 Express 的介绍 |
||
|
|
||
| ### 研讨会 - 入门 | ||
| 要开始完整的研讨会,请确保安装了 Node JS。运行以下命令: | ||
| 阅读本教程前,请确保你已经安装了 Node JS。运行以下命令: | ||
|
|
||
| ``` | ||
| npm install | ||
| npm start | ||
| ``` | ||
|
|
||
| 然后服务器应该在 `localhost:3000` 上启动。 | ||
| 服务器将会在 `localhost:3000` 上启动。 | ||
|
|
||
| 该服务器使用 `mongodb-memory-server` 将MongoDB以内存形式运行为数据库,使用Express处理API端点。 | ||
| 该服务器使用 `mongodb-memory-server` ,将 MongoDB 以内存形式运行为数据库并使用Express处理 API 端点。 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Express前后少了空格 |
||
|
|
||
| 如果你想挑战一下,使用`skeleton`分支(`git fetch && git checkout skeleton`),你可以自己填写API端点的实现。 | ||
| 如果你想挑战一下使用 `skeleton` 分支(`git fetch && git checkout skeleton`),你可以自己填写 API 端点的实现。 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这句话不通顺,没看懂,啥叫 你可以自己填写 API 端点的实现。 |
||
|
|
||
| ### 什么是API? | ||
|
|
||
| API 代表应用程序编程接口。简而言之,API 是一种从你自己的程序访问在服务器上运行的数据和服务的方式。一个很好的公开可用的 API 的例子是 Dog API(确实叫这个)位于https://dog.ceo/dog-api/。你可以通过点击每个路由下列出的 “JSON” 按钮,访问有关 Dog 的各种有趣信息。试试看! | ||
| API 是应用程序编程接口。简而言之,API 是一种从你自己的程序访问在服务器上运行的数据和服务的方式。一个很好的公开可用的 API 的例子是 Dog API,它位于 https://dog.ceo/dog-api/ 。你可以通过点击每个路由下列出的 “JSON” 按钮,访问有关 Dog 的各种有趣信息。 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 访问有关 Dog 的各种有趣信息。这句话的 dog 是可以翻译为中文的。然后试试看可以保留成为更地道的描述。 |
||
|
|
||
| 你会注意到你将被重定向到一个包含一些文本的网页,文本使用花括号‘{}’格式化。你看到的是一个以 JSON(JavaScript对象表示法)表示的 JavaScript 对象。JS 对象本质上是 Python 字典或 C++ 映射,它的功能是将键映射到值。实际上 JavaScript 中的几乎所有东西都是一个对象(另一则故事),所以这很重要。它之所以重要的另一个原因是 JSON 是在 Web 中传输数据的标准方式,所以例如当你在网站上注册账户时,发送到Web服务器的数据是 JSON 格式的。此外, MongoDB 将其信息存储在 JavaScript 对象中。 | ||
| 你将被重定向到一个包含一些文本的网页,文本使用花括号‘{}’格式化。你看到的是一个以 JSON(JavaScript对象表示法)表示的 JavaScript 对象。JS 对象本质上是 Python 字典或 C++ 映射,它的功能是将键映射到值。实际上 JavaScript 中的几乎所有东西都是一个对象,所以这很重要。它之所以重要的另一个原因是 JSON 是在 Web 中传输数据的标准方式,所以例如当你在网站上注册账户时,发送到Web服务器的数据是 JSON 格式的。此外, MongoDB 将其信息存储在 JavaScript 对象中。 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| 酷的是你可以将这些 API 调用传递到你的 Web 程序中,以便从应用程序中访问返回的数据。这使我们能够集成来自我们自己代码中的公共 API(以及TreeHacks赞助商提供的私有API)的各种有趣信息。我们将在研讨会中演示如何使用 Dog API 做到这一点! | ||
| 你可以将这些 API 调用传递到你的 Web 程序中,以便从应用程序中访问返回的数据。这使我们能够集成来自我们自己代码中的公共 API 的各种有趣信息。我们将在教程中演示如何使用 Dog API 做到这一点! | ||
|
|
||
| ### 前端与后端,单手揭示互联网的魔法 | ||
| ### 前端与后端 | ||
|
|
||
| 有没有想过互联网是如何工作的?非常简单,当你访问一个网站时,你正在从某个服务器接收一堆 JavaScript、CSS 和 HTML 文件,然后由你的 Web 浏览器运行。在你的浏览器中运行的代码是前端,提供信息的服务器上运行的代码是后端。Web 开发包括编写在两端都运行的代码(全栈开发),人们专门从事其中一方。API本质上是从后端提供资源的代码。由于我们正在构建一个 Web API,我们的研讨会的重点将放在构建后端上。 | ||
| 有没有想过互联网是如何工作的?非常简单,当你访问一个网站时,你会从某个服务器接收一堆 JavaScript、CSS 和 HTML 文件,然后由你的 Web 浏览器运行。在你的浏览器中运行的代码是前端,提供信息的服务器上运行的代码是后端。Web 开发包括编写在两端都运行的代码(全栈开发),人们专门从事其中一方。API 本质上是从后端提供资源的代码。由于我们正在构建一个 Web API,本教程的重点将放在构建后端上。 | ||
|
|
||
| ### 为动物收容所构建社交网络 | ||
|
|
||
| 在研讨会中,我们将假装构建一个 Web API,供一家假设的动物收容所使用。基本上,动物收容所希望能够随机将动物分配给新主人。由于他们位于硅谷,他们还希望在这个操作之上建立一个社交网络,以便能够查看哪些狗主人是朋友,以便协调狗主人的聚会。他们来到 TreeHacks 找一些聪明的大学生为他们完成这个任务,价格便宜。 | ||
|
|
||
| 为了完成这项任务,我们将使用 Node 和 Express 构建一个 Web API,该 API 与 Dog API 进行交互,以及一个相应的前端,允许动物收容所查看有关他们的用户的所有信息。我们希望支持添加人员和将庇护所的狗分配给他们的操作,查看所有狗主人,在两个狗主人之间添加朋友关系,显示狗主人的朋友以组织聚会,并从数据库中删除一个狗主人,以防其狗死亡...(我们想不出更好的理由了,抱歉,我知道这很黑暗,但知道如何做是很重要的,RIP)。 | ||
|
|
||
| ### 资源 | ||
|
|
||
| 你可以在这个 GitHub 仓库的 Master 分支下访问我们的 Web API 的全部代码,并查看我们演示中使用的幻灯片! | ||
|
|
||
| Mozilla 还有一个名为 MDN 的出色文档网站,详细介绍了你可能想了解的有关 Web 开发的任何东西。他们有一个很好的文本指南,介绍了 Web 开发的入门知识:https://developer.mozilla.org/en-US/docs/Learn | ||
|
|
||
| 我们使用的幻灯片是由 TheNetNinja YouTube 频道的 REST API 教程播放列表慷慨提供的。他更深入地解释了构建 REST API 时正在发生的事情,同时使用 React 构建了一个很棒的应用程序,扩展了前端开发方面。你可以在这里查看:https://www.youtube.com/playlist?list=PL4cUxeGkcC9jBcybHMTIia56aV21o2cZ8 | ||
|
|
||
| 在本教程中,我们将构建一个 Web API,供一家的动物收容所使用。事实上,动物收容所希望能够随机将动物分配给新主人。由于他们位于硅谷,他们还希望在这个操作之上建立一个社交网络,以便能够查看哪些狗主人是朋友,以便协调狗主人的聚会。 | ||
|
|
||
| 为了完成这项任务,我们将使用 Node 和 Express 构建一个 Web API,该 API 与 Dog API 进行交互,以及一个相应的前端,允许动物收容所查看有关他们的用户的所有信息。我们的 Web API 支持添加人员和将庇护所的狗分配给他们的操作,查看所有狗主人的社交网络,在两个狗主人之间添加朋友关系,显示狗主人的朋友以组织聚会,并从数据库中删除一个狗主人。 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改成 NodeJS:Web API 教程