Skip to content

Commit ca755c8

Browse files
committed
docs: update to v2.4.1
1 parent ea42aea commit ca755c8

File tree

84 files changed

+8199
-1069
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+8199
-1069
lines changed

Scripting Documentation/doc.json

Lines changed: 144 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,32 @@
9393
}
9494
]
9595
},
96+
{
97+
"title": {
98+
"en": "Control Widget",
99+
"zh": "控制中心的小组件"
100+
},
101+
"subtitle": {
102+
"en": "Add custom Button or Toggle controls to the Control Center or Lock Screen",
103+
"zh": "在控制中心或锁屏界面添加按钮(Button)或开关(Toggle)控件。"
104+
},
105+
"readme": "control_widget/"
106+
},
107+
{
108+
"title": {
109+
"en": "AppIntent",
110+
"zh": "AppIntent"
111+
},
112+
"subtitle": {
113+
"en": "This interface serves as the core mechanism for executing script logic behind controls in Widgets, Live Activities, and ControlWidgets.",
114+
"zh": "AppIntent 为小组件,灵动岛和控制中心的控件提供了执行脚本逻辑的核心机制。"
115+
},
116+
"keywords": [
117+
"AppIntentManager",
118+
"AppIntentProtocol"
119+
],
120+
"readme": "app_intents/"
121+
},
96122
{
97123
"title": {
98124
"en": "Intent",
@@ -563,6 +589,17 @@
563589
},
564590
"readme": "views/link/"
565591
},
592+
{
593+
"title": {
594+
"en": "SVG",
595+
"zh": "SVG"
596+
},
597+
"subtitle": {
598+
"en": "This view can be used to render SVG images.",
599+
"zh": "这个视图可以用来渲染SVG图像。"
600+
},
601+
"readme": "views/svg/"
602+
},
566603
{
567604
"title": {
568605
"en": "Menu",
@@ -2181,6 +2218,28 @@
21812218
"zh": "该修饰符用于为视图层级提供翻译服务的上下文环境。"
21822219
},
21832220
"readme": "view_modifiers/translation_host/"
2221+
},
2222+
{
2223+
"title": {
2224+
"en": "layoutPriority",
2225+
"zh": "布局优先级"
2226+
},
2227+
"subtitle": {
2228+
"en": "This view modifier specifies a layout priority for a view.",
2229+
"zh": "该修饰符用于为视图指定布局优先级。"
2230+
},
2231+
"readme": "view_modifiers/layout_priority/"
2232+
},
2233+
{
2234+
"title": {
2235+
"en": "Chaining View Modifiers",
2236+
"zh": "可链式调用的修饰符"
2237+
},
2238+
"subtitle": {
2239+
"en": "This view modifier allows you to chain multiple modifiers together, supporting the same modifier being used multiple times in the same view.",
2240+
"zh": "该修饰符可用于连续调用多个修饰符,支持同一个修饰符在同一个视图中多次使用。"
2241+
},
2242+
"readme": "view_modifiers/modifiers/"
21842243
}
21852244
]
21862245
},
@@ -2211,6 +2270,17 @@
22112270
],
22122271
"readme": "interactive_widget_and_liveactivity/"
22132272
},
2273+
{
2274+
"title": {
2275+
"en": "Custom Keyboard",
2276+
"zh": "自定义键盘"
2277+
},
2278+
"subtitle": {
2279+
"en": "Create custom keyboards with unique layouts and functionalities.",
2280+
"zh": "创建具有独特布局和功能的自定义键盘。"
2281+
},
2282+
"readme": "custom_keyboard/"
2283+
},
22142284
{
22152285
"title": {
22162286
"en": "Assistant",
@@ -2243,7 +2313,9 @@
22432313
"zh": "你可以通过该接口访问当前脚本的运行信息、终止脚本并返回结果、在脚本之间调用、以及生成 URL Scheme 以打开或运行脚本。"
22442314
},
22452315
"readme": "script/",
2246-
"keywords": ["URL Scheme"]
2316+
"keywords": [
2317+
"URL Scheme"
2318+
]
22472319
},
22482320
{
22492321
"title": {
@@ -2258,7 +2330,7 @@
22582330
{
22592331
"title": {
22602332
"en": "Data",
2261-
"zh": "数据"
2333+
"zh": "二进制数据(Data)"
22622334
},
22632335
"subtitle": {
22642336
"en": "This class represents binary data and provides methods to convert between various formats.",
@@ -3235,7 +3307,9 @@
32353307
"en": "This interface allows you to send messages using the device's messaging capabilities, such as SMS or iMessage.",
32363308
"zh": "该接口允许您使用设备的消息功能发送信息,例如短信或 iMessage。"
32373309
},
3238-
"keywords": ["MessageUI"],
3310+
"keywords": [
3311+
"MessageUI"
3312+
],
32393313
"readme": "message_ui/"
32403314
},
32413315
{
@@ -3276,6 +3350,73 @@
32763350
"zh": "该接口提供语言翻译功能,允许您在不同语言之间翻译文本。"
32773351
},
32783352
"readme": "translation/"
3353+
},
3354+
{
3355+
"title": {
3356+
"en": "Bluetooth",
3357+
"zh": "蓝牙"
3358+
},
3359+
"subtitle": {
3360+
"en": "This interface provides classes to scan, connect, and exchange data with Bluetooth devices.",
3361+
"zh": "提供蓝牙相关的API,允许你扫描、连接和与蓝牙设备交换数据。"
3362+
},
3363+
"children": [
3364+
{
3365+
"title": {
3366+
"en": "BluetoothCentralManager",
3367+
"zh": "蓝牙中央设备管理器"
3368+
},
3369+
"subtitle": {
3370+
"en": "This interface allows you to scan for, connect to, and interact with nearby Bluetooth peripherals.",
3371+
"zh": "该接口允许你扫描、连接和与附近的蓝牙外设进行交互。"
3372+
},
3373+
"readme": "bluetooth/central_manager/"
3374+
},
3375+
{
3376+
"title": {
3377+
"en": "BluetoothPeripheral",
3378+
"zh": "蓝牙外设"
3379+
},
3380+
"subtitle": {
3381+
"en": "This interface provides properties and methods for interacting with the device, including connecting, discovering services and characteristics, reading/writing values, and subscribing to notifications.",
3382+
"zh": "表示一个 BLE 外围设备对象,支持读取设备信息、连接状态、发现服务与特征值、读取写入数据、订阅通知等。"
3383+
},
3384+
"readme": "bluetooth/peripheral/"
3385+
},
3386+
{
3387+
"title": {
3388+
"en": "BluetoothService",
3389+
"zh": "蓝牙服务"
3390+
},
3391+
"subtitle": {
3392+
"en": "This interface represents a Bluetooth Low Energy (BLE) service. A service is a logical grouping of related characteristics and possibly other included services.",
3393+
"zh": "表示一个 BLE(低功耗蓝牙)服务。服务是外围设备中功能的逻辑分组,包含一个或多个特征值(`Characteristic`),也可以包含对其他服务的引用(包含服务)。"
3394+
},
3395+
"readme": "bluetooth/service/"
3396+
},
3397+
{
3398+
"title": {
3399+
"en": "BluetoothCharacteristic",
3400+
"zh": "蓝牙服务特征值"
3401+
},
3402+
"subtitle": {
3403+
"en": "This interface represents a Bluetooth Low Energy (BLE) service. A service is a logical grouping of related characteristics and possibly other included services.",
3404+
"zh": "表示蓝牙服务(`BluetoothService`)中的一个特征值,是 BLE 设备数据交互的核心单元。"
3405+
},
3406+
"readme": "bluetooth/characteristic/"
3407+
},
3408+
{
3409+
"title": {
3410+
"en": "BluetoothPeripheralManager",
3411+
"zh": "蓝牙外设管理器"
3412+
},
3413+
"subtitle": {
3414+
"en": "This interface allows you to create a Bluetooth peripheral that can advertise services and characteristics, and accept connections from central devices.",
3415+
"zh": "该接口允许你创建一个蓝牙外设,可以广播服务和特征,并接受来自中央设备的连接。"
3416+
},
3417+
"readme": "bluetooth/peripheral_manager/"
3418+
}
3419+
]
32793420
}
32803421
]
32813422
}

Scripting Documentation/location/en.md

Lines changed: 61 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The global `Location` API provides access to the device’s geographic location, including one-time location retrieval, reverse geocoding, user-driven location selection via map, and accuracy control. It also supports permission checking for widgets that need location updates.
1+
The global `Location` API provides access to the device’s geographic location, including one-time location retrieval, reverse geocoding, user-driven location selection via map, accuracy control, and permission checking for widgets.
22

33
---
44

@@ -51,23 +51,32 @@ await Location.setAccuracy("hundredMeters")
5151

5252
---
5353

54-
### `Location.requestCurrent(): Promise<LocationInfo | null>`
54+
### `Location.requestCurrent(options?: { forceRequest?: boolean }): Promise<LocationInfo | null>`
5555

5656
Requests the user's current location once. May trigger a permission prompt if not previously granted.
5757

58+
By default, if a cached location is available, it will be returned immediately. If no cached location exists, a new request will be made. To force a new location retrieval even if a cached value exists, pass `{ forceRequest: true }`.
59+
60+
#### Parameters
61+
62+
| Option | Type | Required | Description |
63+
| -------------- | --------- | -------- | --------------------------------------------------------------- |
64+
| `forceRequest` | `boolean` | No | If `true`, bypasses the cache and always requests new location. |
65+
5866
```ts
59-
const location = await Location.requestCurrent()
67+
const location = await Location.requestCurrent({ forceRequest: true })
6068
if (location) {
6169
console.log("Latitude:", location.latitude)
6270
console.log("Longitude:", location.longitude)
71+
console.log("Timestamp:", location.timestamp)
6372
}
6473
```
6574

6675
---
6776

6877
### `Location.pickFromMap(): Promise<LocationInfo | null>`
6978

70-
Opens the built-in map interface to allow the user to pick a location manually.
79+
Opens the built-in map interface to allow the user to manually select a location.
7180

7281
```ts
7382
const selected = await Location.pickFromMap()
@@ -110,7 +119,7 @@ if (placemarks?.length) {
110119

111120
### `LocationAccuracy`
112121

113-
Specifies the accuracy of the location data:
122+
Specifies the desired accuracy of location data:
114123

115124
```ts
116125
type LocationAccuracy =
@@ -125,20 +134,30 @@ type LocationAccuracy =
125134
126135
### `LocationInfo`
127136
128-
Represents a geographic coordinate:
137+
Represents a geographic coordinate with timestamp:
129138
130139
```ts
131140
type LocationInfo = {
141+
/**
142+
* The latitude in degrees.
143+
*/
132144
latitude: number
145+
/**
146+
* The longitude in degrees.
147+
*/
133148
longitude: number
149+
/**
150+
* Timestamp of when the location was recorded, in milliseconds since epoch.
151+
*/
152+
timestamp: number
134153
}
135154
```
136155
137156
---
138157
139158
### `LocationPlacemark`
140159
141-
Represents a human-readable description of a geographic coordinate, typically returned by reverse geocoding. It contains structured location details, such as street, city, region, country, and points of interest.
160+
Represents a human-readable description of a geographic coordinate, typically returned by reverse geocoding. Includes structured location details such as city, country, and street.
142161
143162
```ts
144163
type LocationPlacemark = {
@@ -161,30 +180,32 @@ type LocationPlacemark = {
161180
}
162181
```
163182
164-
### Field Descriptions
165-
166-
| Field | Type | Description |
167-
| ----------------------- | -------------- | -------------------------------------------------------------------------------------------- |
168-
| `location` | `LocationInfo` | The latitude and longitude of the placemark (usually the same as the reverse geocode input). |
169-
| `region` | `string` | A general regional name, such as a province or state. |
170-
| `timeZone` | `string` | The time zone identifier (e.g., `"Asia/Shanghai"`). |
171-
| `name` | `string` | A generic name for the place, such as a building or landmark. |
172-
| `thoroughfare` | `string` | The street name, such as `"Main Street"` or `"Zhongguancun Ave"`. |
173-
| `subThoroughfare` | `string` | Additional street-level info, such as building number `"123"` or unit info. |
174-
| `locality` | `string` | The city or town name. |
175-
| `subLocality` | `string` | A sub-area of the city or town, such as a neighborhood or district. |
176-
| `administrativeArea` | `string` | The state, province, or similar administrative region. |
177-
| `subAdministrativeArea` | `string` | A further subdivision within the administrative area, such as a county or district. |
178-
| `postalCode` | `string` | The postal or ZIP code. |
179-
| `isoCountryCode` | `string` | The ISO 3166-1 alpha-2 country code (e.g., `"US"`, `"CN"`). |
180-
| `country` | `string` | The full name of the country or region. |
181-
| `inlandWater` | `string` | The name of a nearby inland body of water (lake, river), if applicable. |
182-
| `ocean` | `string` | The name of a nearby ocean, if applicable. |
183-
| `areasOfInterest` | `string[]` | An array of nearby points of interest or landmarks (e.g., `"Times Square"`). |
183+
#### Field Descriptions
184+
185+
| Field | Type | Description |
186+
| ----------------------- | -------------- | ------------------------------------------------------------------------------- |
187+
| `location` | `LocationInfo` | The coordinates of the placemark (typically the same as reverse geocode input). |
188+
| `region` | `string` | General region or province/state. |
189+
| `timeZone` | `string` | Time zone identifier (e.g., `"Asia/Shanghai"`). |
190+
| `name` | `string` | Generic name such as building, landmark, or area. |
191+
| `thoroughfare` | `string` | Street name (e.g., `"Main St"`, `"Zhongguancun Ave"`). |
192+
| `subThoroughfare` | `string` | Street-level detail like building number or unit. |
193+
| `locality` | `string` | City or town. |
194+
| `subLocality` | `string` | Subdivision of the locality (e.g., neighborhood or district). |
195+
| `administrativeArea` | `string` | Province, state, or equivalent administrative area. |
196+
| `subAdministrativeArea` | `string` | Further subdivision like county or district. |
197+
| `postalCode` | `string` | ZIP or postal code. |
198+
| `isoCountryCode` | `string` | ISO 3166-1 alpha-2 country code (e.g., `"US"`, `"CN"`). |
199+
| `country` | `string` | Full name of the country or region. |
200+
| `inlandWater` | `string` | Name of nearby inland water (river/lake), if applicable. |
201+
| `ocean` | `string` | Name of nearby ocean, if applicable. |
202+
| `areasOfInterest` | `string[]` | List of nearby points of interest or landmarks (e.g., `"Times Square"`). |
184203
185204
---
186205
187-
#### Example Usage
206+
## Example Usage
207+
208+
### Reverse Geocode
188209
189210
```ts
190211
const placemarks = await Location.reverseGeocode({
@@ -206,9 +227,7 @@ if (placemarks?.length) {
206227

207228
---
208229

209-
#### Suggested Address Formatter
210-
211-
You can use the following function to construct a compact, readable address string:
230+
### Address Formatter (Helper)
212231

213232
```ts
214233
function formatAddress(p: LocationPlacemark): string {
@@ -225,18 +244,20 @@ function formatAddress(p: LocationPlacemark): string {
225244

226245
---
227246

228-
#### Practical Use Cases
247+
## Best Practices & Use Cases
229248

230-
* Use `areasOfInterest` and `name` to display user-friendly labels (e.g., “Empire State Building”).
231-
* Use `postalCode`, `locality`, and `administrativeArea` for auto-filling forms or location tagging.
232-
* Use `timeZone` for generating time-sensitive notifications or scheduling events in the user’s local time.
233-
* Combine `thoroughfare` and `subThoroughfare` for a complete street address.
249+
* Use `areasOfInterest` and `name` to display user-friendly place names.
250+
* Use `postalCode`, `locality`, and `administrativeArea` for autofill and geotagging.
251+
* Use `timestamp` to determine freshness of location data.
252+
* Use `timeZone` for localizing time-based features.
253+
* Set location accuracy before calling `requestCurrent` for optimal precision.
254+
* Always check widget permissions via `isAuthorizedForWidgetUpdates()`.
234255

235256
---
236257

237258
## Notes
238259

239-
* Reverse geocoding may return multiple placemarks; typically, the first one is the most relevant.
240-
* `null` is returned if the location or geocoding fails.
241-
* You should call `setAccuracy` before `requestCurrent` to control precision based on your use case.
242-
* When used in widgets, permissions may be limited; use `isAuthorizedForWidgetUpdates` to verify access.
260+
* Reverse geocoding may return multiple results. Use the first placemark for best relevance.
261+
* If location retrieval fails, `null` is returned.
262+
* When `forceRequest` is false or omitted, cached location may be used for faster results.
263+
* In widgets, location access may be restricted. Always verify permissions explicitly.

0 commit comments

Comments
 (0)