1
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
## 1.0.3(2025-07-25)
|
||||
* 兼容原生鸿蒙
|
||||
## 1.0.2(2025-04-13)
|
||||
* IOS端现在支持指定震动频率.
|
||||
## 1.0.1(2025-02-10)
|
||||
* 兼容微信
|
||||
## 1.0.1(2025-07-25)
|
||||
* 兼容原生鸿蒙
|
||||
## 1.0.0(2024-06-01)
|
||||
使用手机震动
|
||||
安卓,ios支持。
|
||||
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"id": "x-vibrate-s",
|
||||
"displayName": "x-vibrate-s",
|
||||
"version": "1.0.1",
|
||||
"description": "x-vibrate-s",
|
||||
"keywords": [
|
||||
"x-vibrate-s"
|
||||
],
|
||||
"repository": "",
|
||||
"engines": {
|
||||
"HBuilderX": "^3.6.8"
|
||||
},
|
||||
"dcloudext": {
|
||||
"type": "uts",
|
||||
"sale": {
|
||||
"regular": {
|
||||
"price": "0.00"
|
||||
},
|
||||
"sourcecode": {
|
||||
"price": "0.00"
|
||||
}
|
||||
},
|
||||
"contact": {
|
||||
"qq": ""
|
||||
},
|
||||
"declaration": {
|
||||
"ads": "",
|
||||
"data": "",
|
||||
"permissions": ""
|
||||
},
|
||||
"npmurl": ""
|
||||
},
|
||||
"uni_modules": {
|
||||
"dependencies": [],
|
||||
"encrypt": [],
|
||||
"platforms": {
|
||||
"cloud": {
|
||||
"tcb": "u",
|
||||
"aliyun": "u",
|
||||
"alipay": "u"
|
||||
},
|
||||
"client": {
|
||||
"Vue": {
|
||||
"vue2": "u",
|
||||
"vue3": "u"
|
||||
},
|
||||
"App": {
|
||||
"app-android": "u",
|
||||
"app-ios": "u"
|
||||
},
|
||||
"H5-mobile": {
|
||||
"Safari": "u",
|
||||
"Android Browser": "u",
|
||||
"微信浏览器(Android)": "u",
|
||||
"QQ浏览器(Android)": "u"
|
||||
},
|
||||
"H5-pc": {
|
||||
"Chrome": "u",
|
||||
"IE": "u",
|
||||
"Edge": "u",
|
||||
"Firefox": "u",
|
||||
"Safari": "u"
|
||||
},
|
||||
"小程序": {
|
||||
"微信": "u",
|
||||
"阿里": "u",
|
||||
"百度": "u",
|
||||
"字节跳动": "u",
|
||||
"QQ": "u",
|
||||
"钉钉": "u",
|
||||
"快手": "u",
|
||||
"飞书": "u",
|
||||
"京东": "u"
|
||||
},
|
||||
"快应用": {
|
||||
"华为": "u",
|
||||
"联盟": "u"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
# x-vibrate-s
|
||||
|
||||
### 兼容性
|
||||
|
||||
| Harmony | IOS | Android | WEB | 小程序 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 支持 | 支持 | 支持 | 支持 | 支持 |
|
||||
|
||||
### 开发文档
|
||||
|
||||
鸿蒙使用了:ohos.permission.VIBRATE 权限
|
||||
|
||||
调用:
|
||||
```ts
|
||||
import { vibrator } from "@/uni_modules/x-vibrate-s"
|
||||
// 使用,ios13+支持指定频率震动,ios12及以下不支持.
|
||||
vibrator(50)
|
||||
|
||||
```
|
||||
|
||||
参数配置:
|
||||
|
||||
|
||||
```uts
|
||||
/**
|
||||
* 震动
|
||||
* @param {number} duriation 震动时间单位ms,ios(12及以下)无效
|
||||
*/
|
||||
vibrator(duriation : number):boolean
|
||||
|
||||
```
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
|
||||
package="io.dcloud.uni_modules.xVibrateS">
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
</manifest>
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"minSdkVersion": "19"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import Vibrator from "android.os.Vibrator"
|
||||
import Context from 'android.content.Context'
|
||||
|
||||
/**
|
||||
* 震动
|
||||
* @param {number} duriation 震动时间单位ms
|
||||
*/
|
||||
export function vibrator(duriation : number):boolean {
|
||||
try {
|
||||
const context = UTSAndroid.getAppContext() as Context
|
||||
let vb = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator;
|
||||
if (vb!.hasVibrator()) {
|
||||
vb!.vibrate(duriation.toLong());
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"x_library_s": "./lib/x_library_s.har"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import { x_vibrator } from "x_library_s";
|
||||
import { BusinessError } from "@kit.BasicServicesKit";
|
||||
|
||||
/**
|
||||
* 震动
|
||||
* @param {number} duriation 震动时间单位ms
|
||||
*/
|
||||
export function vibrator(duriation : number) : boolean {
|
||||
try {
|
||||
x_vibrator(duriation)
|
||||
} catch (err) {
|
||||
let e : BusinessError = err as BusinessError;
|
||||
console.error(e.message);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSPrivacyAccessedAPITypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyCollectedDataTypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyTracking</key>
|
||||
<false/>
|
||||
<key>NSPrivacyTrackingDomains</key>
|
||||
<array/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"deploymentTarget": "9"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import * as AudioToolbox from 'AudioToolbox';
|
||||
import * as UIKit from 'UIKit';
|
||||
import { Thread } from 'Foundation';
|
||||
|
||||
|
||||
/**
|
||||
* 震动
|
||||
* @param {number} duriation 震动时间单位ms,ios 13.+有用。
|
||||
*/
|
||||
export function vibrator(duriation : number):boolean {
|
||||
if (UTSiOS.available("iOS 13.0, *")) {
|
||||
let generator = new UIKit.UIImpactFeedbackGenerator(style = UIKit.UIImpactFeedbackGenerator.FeedbackStyle.medium)
|
||||
generator.prepare();
|
||||
let start = new Date().getTime();
|
||||
let end = start + duriation
|
||||
while(start<end){
|
||||
generator.impactOccurred(intensity = 0.5);
|
||||
Thread.sleep(forTimeInterval = 0.1)
|
||||
start = new Date().getTime();
|
||||
}
|
||||
}else{
|
||||
AudioToolbox.AudioServicesPlayAlertSound(AudioToolbox.kSystemSoundID_Vibrate)
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* 震动
|
||||
* @param {number} duriation 震动时间单位ms,ios,微信没有用。
|
||||
*/
|
||||
export function vibrator(duriation : number):boolean {
|
||||
wx.vibrateShort({
|
||||
type:"medium",
|
||||
success() {
|
||||
|
||||
},
|
||||
fail(error) {
|
||||
console.error("微信:震动失败")
|
||||
}
|
||||
})
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* 震动
|
||||
* @param {number} duriation 震动时间单位ms,ios,微信没有用。
|
||||
*/
|
||||
export function vibrator(duriation : number):boolean {
|
||||
try {
|
||||
navigator.vibrate(duriation);
|
||||
} catch (error) {
|
||||
console.error("WEB震动失败:",error)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user