Skip to content
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

58 setting up access to arkit data #134

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions project/visionos/Markdown/setting-up-access-to-arkit-data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# 设置对 ARKit 数据的访问

检查你的应用是否可以使用 ARKit 并尊重用户隐私。

## 概述

<p style="width: 100%; padding:0px;" >
<img src="https://docs-assets.developer.apple.com/published/caa9cb3bdf25ecb38b21c5e8343b93d1/[email protected]" align="right" width="50%" height="auto" alt="截图显示了手部追踪的系统权限提示。选项有 '不允许' 和 '确定'。特定应用的用法说明是跟踪你的手以检测心形手势。"/>

在 visionOS 中,ARKit 可利用手部追踪和世界感应等数据实现全新体验。系统会对此类敏感信息的访问权限进行把关。由于用户可以拒绝应用使用 ARKit 数据的请求或稍后撤销访问权限,因此你需要提供使用应用的替代方案,并处理应用失去数据访问权限的情况。

<br></br>
<br></br>
<br></br>

</p>

### 为 ARKit 数据访问添加使用说明

用户需要知道你的应用为什么要访问 ARKit 中的数据。将以下键添加到你应用的信息属性列表中,以提供面向用户的使用说明,以解释应用如何使用数据:

[`NSHandsTrackingUsageDescription`](https://developer.apple.com/documentation/bundleresources/information_property_list/nshandstrackingusagedescription)
如果应用使用手部追踪,请使用此键。

[`NSWorldSensingUsageDescription`](https://developer.apple.com/documentation/bundleresources/information_property_list/nsworldsensingusagedescription)
如果应用使用图像追踪、平面检测或场景重建,请使用此键。

> 备注
> 世界追踪与世界感知不同,不需要授权。更多信息,请参阅[追踪世界空间中的特定点](https://developer.apple.com/documentation/visionos/tracking-points-in-world-space)。

### 选择预先授权或按需授权

你可以选择让用户看到 ARKit 数据授权请求的时间点。如果你需要精确控制请求出现的时间,可调用 [`ARKitSession`](https://developer.apple.com/documentation/arkit/arkitsession) 中的 [`requestAuthorization(for:)`](https://developer.apple.com/documentation/arkit/arkitsession/4131678-requestauthorization) 方法,在调用该方法时明确请求授权。否则,用户会在 [`run(_:)`](https://developer.apple.com/documentation/arkit/arkitsession/4131679-run) 方法被调用时看到授权请求。这是一种隐式授权,因为请求的时间完全取决于何时启动会话。

### 打开空间并运行会话

为帮助保护用户隐私,只有当你的应用显示“完整空间”且其他应用隐藏时,才能使用 ARKit 数据。在调用 [`run(_:)`](https://developer.apple.com/documentation/arkit/arkitsession/4131679-run) 方法之前,请选择一种空间样式并展示。

下面示例了一个使用 ARKit 设置空间的应用结构体:

```swift
@main
struct MyApp: App {
@State var session = ARKitSession()
@State var immersionState: ImmersionStyle = .mixed
var body: some Scene {
WindowGroup {
ContentView()
}
ImmersiveSpace(id: "appSpace") {
MixedImmersionView()
.task {
let planeData = PlaneDetectionProvider(alignments: [.horizontal])

if PlaneDetectionProvider.isSupported {
do {
try await session.run([planeData])
for await update in planeData.anchorUpdates {
// Update app state.
}
} catch {
print("ARKit session error \(error)")
}
}
}
}
.immersionStyle(selection: $immersionState, in: .mixed)
}
}
```

从应用的用户界面调用 [`openImmersiveSpace`](https://developer.apple.com/documentation/SwiftUI/EnvironmentValues/openImmersiveSpace) 以创建空间,运行 ARKit 会话,并启动沉浸式体验。下面的示例是一个简单的视图,其中有一个能打开空间的按钮:

```swift
struct ContentView: View {
@Environment(\.openImmersiveSpace) private var openImmersiveSpace

var body: some View {
Button("Start ARKit experience") {
Task {
await openImmersiveSpace(id: "appSpace")
}
}
}
}
```

### 为被拒绝和撤销的授权提供替代方案

用户可能拒绝授权应用访问 ARKit 数据,或者他们可能选择稍后在“设置”中撤销该访问权限。请优雅地对应这些情况,并删除或转换依赖 ARKit 数据的内容。例如,你可以淡出需要移除的内容,或将内容重新调整到适当的起始位置。如果你的应用使用 ARKit 数据在用户周围放置内容,请考虑让用户使用系统提供的界面放置内容。

如果你使用 ARKit 获取用户输入,提供替代方案尤为重要。使用无障碍功能、触控板、键盘或其他输入形式的用户可能需要一种在没有 ARKit 的情况下使用应用的方法。

---

## 另见

### ARKit

- [快乐光束](https://developer.apple.com/documentation/visionos/happybeam)
使用 ARKit 在 Full Space 中创建有趣的游戏。
- [在沉浸式体验中融入真实世界的环境](https://developer.apple.com/documentation/visionos/incorporating-real-world-surroundings-in-an-immersive-experience)
让你的应用内容与当地世界的地形相呼应,从而创造身临其境的体验。
- [在检测到的平面上放置内容](https://developer.apple.com/documentation/visionos/placing-content-on-detected-planes)
检测水平平面(如桌子和地板)以及垂直平面(如墙壁和门)。
- [追踪世界空间中的特定点](https://developer.apple.com/documentation/visionos/tracking-points-in-world-space)
检索应用在 ARKit 中存储的锚点的位置和方向。
- [在三维空间中追踪预登记图像](https://developer.apple.com/documentation/visionos/tracking-images-in-3d-space)
根据已知图像的当前位置在用户周围放置内容。
38 changes: 19 additions & 19 deletions project/visionos/setting-up-access-to-arkit-data.yml
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
- 内容: 'Setting up access to ARKit data'
提示: ''
翻译: ''
翻译: '设置对 ARKit 数据的访问'
- 内容: 'Check whether your app can use ARKit and respect people’s privacy.'
提示: ''
翻译: ''
翻译: '检查你的应用是否可以使用 ARKit 并尊重用户隐私。'
- 内容: 'Overview'
提示: ''
翻译: ''
翻译: '概述'
- 内容: 'In visionOS, ARKit can enable new kinds of experiences that leverage data such as hand tracking and world sensing. The system gates access to this kind of sensitive information. Because people can decline your app’s request to use ARKit data or revoke access later, you need to provide alternative ways to use your app and to handle cases where your app loses access to data.'
提示: ''
翻译: ''
翻译: '在 visionOS 中,ARKit 可利用手部追踪和世界感应等数据实现全新体验。系统会对此类敏感信息的访问权限进行把关。由于用户可以拒绝应用使用 ARKit 数据的请求或稍后撤销访问权限,因此你需要提供使用应用的替代方案,并处理应用失去数据访问权限的情况。'
- 内容: 'Add usage descriptions for ARKit data access'
提示: ''
翻译: ''
翻译: '为 ARKit 数据访问添加使用说明'
- 内容: 'People need to know why your app wants to access data from ARKit. Add the following keys to your app’s information property list to provide a user-facing usage description that explains how your app uses the data:'
提示: ''
翻译: ''
翻译: 用户需要知道你的应用为什么要访问 ARKit 中的数据。将以下键添加到你应用的信息属性列表中,以提供面向用户的使用说明,以解释应用如何使用数据:'
- 内容: 'Use this key if your app uses hand tracking.'
提示: ''
翻译: ''
翻译: '如果应用使用手部追踪,请使用此键。'
- 内容: 'Use this key if your app uses image tracking, plane detection, or scene reconstruction.'
提示: ''
翻译: ''
翻译: '如果应用使用图像追踪、平面检测或场景重建,请使用此键。'
- 内容: 'Note'
提示: ''
翻译: ''
翻译: '备注'
- 内容: 'World tracking — unlike world sensing — doesn’t require authorization. For more information, see Tracking specific points in world space.'
提示: ''
翻译: ''
翻译: '世界追踪与世界感知不同,不需要授权。更多信息,请参阅追踪世界空间中的特定点。'
- 内容: 'Choose between up-front or as-needed authorization'
提示: ''
翻译: ''
翻译: '选择预先授权或按需授权'
- 内容: 'You can choose when someone sees an authorization request to use ARKit data. If you need precise control over when the request appears, call the requestAuthorization(for:) method on ARKitSession to explicitly authorize access at the time you call it. Otherwise, people see an authorization request when you call the run(_:) method. This is an implicit authorization because the timing of the request depends entirely on when you start the session.'
提示: ''
翻译: ''
翻译: '你可以选择让用户看到 ARKit 数据授权请求的时间点。如果你需要精确控制请求出现的时间,可调用 ARKitSession 中的 requestAuthorization(for:) 方法,在调用该方法时明确请求授权。否则,用户会在 run(_:) 方法被调用时看到授权请求。这是一种隐式授权,因为请求的时间完全取决于何时启动会话。'
- 内容: 'Open a space and run a session'
提示: ''
翻译: ''
翻译: '打开空间并运行会话'
- 内容: 'To help protect people’s privacy, ARKit data is available only when your app presents a Full Space and other apps are hidden. Present one of these space styles before calling the run(_:) method.'
提示: ''
翻译: ''
翻译: '为帮助保护用户隐私,只有当你的应用显示“完整空间”且其他应用隐藏时,才能使用 ARKit 数据。在调用 run(_:) 方法之前,请选择一种空间样式并展示。'
- 内容: 'The following shows an app structure that’s set up to use a space with ARKit:'
提示: ''
翻译: ''
翻译: '下面示例了一个使用 ARKit 设置空间的应用结构体:'
- 内容: 'Call openImmersiveSpace from your app’s user interface to create a space, start running an ARKit session, and kick off an immersive experience. The following shows a simple view with a button that opens the space:'
提示: ''
翻译: ''
翻译: '从应用的用户界面调用 openImmersiveSpace 以创建空间,运行 ARKit 会话,并启动沉浸式体验。下面的示例是一个简单的视图,其中有一个能打开空间的按钮:'
- 内容: 'Provide alternatives for declined and revoked authorizations'
提示: ''
翻译: ''
翻译: '为被拒绝和撤销的授权提供替代方案'
- 内容: 'Someone might not want to give your app access to data from ARKit, or they might choose to revoke that access later in Settings. Handle these situations gracefully, and remove or transition content that depends on ARKit data. For example, you might fade out content that you need to remove, or recenter content to an appropriate starting position. If your app uses ARKit data to place content in a person’s surroundings, consider letting people place content using the system-provided interface.'
提示: ''
翻译: ''
翻译: '用户可能拒绝授权应用访问 ARKit 数据,或者他们可能选择稍后在“设置”中撤销该访问权限。请优雅地对应这些情况,并删除或转换依赖 ARKit 数据的内容。例如,你可以淡出需要移除的内容,或将内容重新调整到适当的起始位置。如果你的应用使用 ARKit 数据在用户周围放置内容,请考虑让用户使用系统提供的界面放置内容。'
- 内容: 'Providing alternatives is especially important if you’re using ARKit for user input. People using accessibility features, trackpads, keyboards, or other forms of input might need a way to use your app without ARKit.'
提示: ''
翻译: ''
翻译: '如果你使用 ARKit 获取用户输入,提供替代方案尤为重要。使用无障碍功能、触控板、键盘或其他输入形式的用户可能需要一种在没有 ARKit 的情况下使用应用的方法。'