Skip to content
Tauri 中文网

触觉

Android 和 iOS 上的触觉反馈和振动。

🌐 Haptic feedback and vibrations on Android and iOS.

Android 上没有关于振动支持的标准/要求,因此反馈 API 可能在价格较低的手机上无法正常工作,包括最近发布的手机。

🌐 There are no standards/requirements for vibration support on Android, so the feedback APIs may not work correctly on more affordable phones, including recently released ones.

🌐 Supported Platforms

This plugin requires a Rust version of at least 1.77.2

Platform Level Notes
windows
linux
macos
android
ios

🌐 Setup

安装触觉插件以开始使用。

🌐 Install the haptics plugin to get started.

使用项目的包管理器添加依赖:

npm run tauri add haptics

🌐 Usage

触觉插件在 JavaScript 中可用。

🌐 The haptics plugin is available in JavaScript.

import {
vibrate,
impactFeedback,
notificationFeedback,
selectionFeedback,
} from '@tauri-apps/plugin-haptics';
await vibrate(1);
await impactFeedback('medium');
await notificationFeedback('warning');
await selectionFeedback();

🌐 Permissions

默认情况下,所有潜在危险的插件命令和作用域都会被阻止,无法访问。你必须在 capabilities 配置中修改权限以启用这些功能。

🌐 By default all potentially dangerous plugin commands and scopes are blocked and cannot be accessed. You must modify the permissions in your capabilities configuration to enable these.

有关更多信息,请参见功能概览,有关使用插件权限的分步指南,请参见分步指南

🌐 See the Capabilities Overview for more information and the step by step guide to use plugin permissions.

src-tauri/capabilities/mobile.json
{
"$schema": "../gen/schemas/mobile-schema.json",
"identifier": "mobile-capability",
"windows": ["main"],
"platforms": ["iOS", "android"],
"permissions": [
"haptics:allow-impact-feedback",
"haptics:allow-notification-feedback",
"haptics:allow-selection-feedback",
"haptics:allow-vibrate"
]
}

Permission Table

Identifier Description

haptics:allow-impact-feedback

Enables the impact_feedback command without any pre-configured scope.

haptics:deny-impact-feedback

Denies the impact_feedback command without any pre-configured scope.

haptics:allow-notification-feedback

Enables the notification_feedback command without any pre-configured scope.

haptics:deny-notification-feedback

Denies the notification_feedback command without any pre-configured scope.

haptics:allow-selection-feedback

Enables the selection_feedback command without any pre-configured scope.

haptics:deny-selection-feedback

Denies the selection_feedback command without any pre-configured scope.

haptics:allow-vibrate

Enables the vibrate command without any pre-configured scope.

haptics:deny-vibrate

Denies the vibrate command without any pre-configured scope.


Tauri 中文网 - 粤ICP备13048890号
Nodejs.cn 旗下网站