no message

This commit is contained in:
hajimi
2026-06-11 12:15:29 +08:00
parent 10ebe39c30
commit 96efa1d905
5859 changed files with 815501 additions and 5 deletions
@@ -0,0 +1,13 @@
## 1.1.32025-09-12
- 鸿蒙平台 新增 打开 url 错误时输出
- iOS平台 修复 语法报黄问题
## 1.1.22025-03-20
- 更新 支持鸿蒙
## 1.1.12024-12-16
- 修复 canOpenURL 在安卓端可能会报类型错误的问题
## 1.1.02024-12-06
- 新增 canOpenURL UTS API,可用此API判断url是否可以跳转
## 1.0.12024-11-13
- 修复 Android 打开部分 schema 时没有跳转到目标应用的 Bug
## 1.0.02024-04-25
- 更新 在 Android 和 iOS 上打开链接的 UTS API
@@ -0,0 +1,124 @@
{
"id": "uts-openSchema",
"displayName": "uts-openSchema",
"version": "1.1.3",
"description": "在 Android、iOS、HarmonyOS 上打开链接的 UTS API",
"keywords": [
"uts-openSchema"
],
"repository": "",
"engines": {
"HBuilderX": "^4.0",
"uni-app": "^4.75",
"uni-app-x": "^4.75"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "无"
},
"npmurl": "",
"darkmode": "x",
"i18n": "x",
"widescreen": "x"
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "√",
"aliyun": "√",
"alipay": "√"
},
"client": {
"uni-app": {
"vue": {
"vue2": {
"extVersion": "1.0.0",
"minVersion": ""
},
"vue3": {
"extVersion": "1.0.0",
"minVersion": ""
}
},
"web": {
"safari": "x",
"chrome": "x"
},
"app": {
"vue": {
"extVersion": "1.0.0",
"minVersion": ""
},
"nvue": "-",
"android": {
"extVersion": "1.0.0",
"minVersion": "21"
},
"ios": {
"extVersion": "1.0.0",
"minVersion": "12"
},
"harmony": {
"extVersion": "1.1.2",
"minVersion": "5.0.0"
}
},
"mp": {
"weixin": "x",
"alipay": "x",
"toutiao": "x",
"baidu": "x",
"kuaishou": "x",
"jd": "x",
"harmony": "x",
"qq": "x",
"lark": "x"
},
"quickapp": {
"huawei": "x",
"union": "x"
}
},
"uni-app-x": {
"web": {
"safari": "x",
"chrome": "x"
},
"app": {
"android": {
"extVersion": "1.0.0",
"minVersion": "21"
},
"ios": {
"extVersion": "1.0.0",
"minVersion": "12"
},
"harmony": {
"extVersion": "1.1.2",
"minVersion": "5.0.0"
}
},
"mp": {
"weixin": "x"
}
}
}
}
}
}
@@ -0,0 +1,59 @@
# uts-openSchema
打开链接,支持:
1. 打开外部 App
2. 使用浏览器打开链接
3. 打开地图到指定地点
4. ...
## 使用
1. 安装此插件
2. 在要使用的地方 `import` 导入
```ts
import { openSchema, canOpenURL } from '@/uni_modules/uts-openSchema'
```
3. 直接调用 `openSchema` 方法:
```ts
// #ifdef UNI-APP-X
// 使用外部浏览器打开指定URL
openSchema('https://uniapp.dcloud.io/uni-app-x')
// #ifdef APP-ANDROID
// Android 使用应用商店打开指定App
openSchema('market://details?id=com.tencent.mm')
// Android 打开地图坐标
// 可以先用canOpenURL判断是否安装了地图软件
if (canOpenURL('androidamap://')) {
openSchema('androidamap://viewMap?sourceApplication=Hello%20uni-app&poiname=DCloud&lat=39.9631018208&lon=116.3406135236&dev=0')
} else {
console.log('未安装高德地图')
}
// #endif -->
// #ifdef APP-IOS
// 打开 AppStore 到搜索页
openSchema('itms-apps://search.itunes.apple.com//WebObjects//MZSearch.woa/wa/search?media=software&lterm=')
// 打开 iOS 地图坐标
openSchema('http://maps.apple.com/?q=Mexican+Restaurant&sll=50.894967,4.341626&z=10&t=s')
// #endif -->
// #endif -->
```
### 参数
- openSchema(url: string) // `url`:要打开的链接 `必填` `不为空字符串`
## 相关开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts)
@@ -0,0 +1,3 @@
{
"minSdkVersion": "21"
}
@@ -0,0 +1,27 @@
import Intent from 'android.content.Intent'
import Uri from 'android.net.Uri'
import { OpenSchema, CanOpenURL } from '../interface.uts'
export const openSchema : OpenSchema = function (url : string) {
if (canOpenURL(url)) {
const context = UTSAndroid.getUniActivity()!
const uri = Uri.parse(url)
const intent = new Intent(Intent.ACTION_VIEW, uri)
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.setData(uri)
context.startActivity(intent)
} else {
console.error('[uts-openSchema] url param Error', JSON.stringify(url))
}
}
export const canOpenURL : CanOpenURL = function (url : string) : boolean {
if (typeof url === 'string' && url.length > 0) {
const context = UTSAndroid.getUniActivity()!
const uri = Uri.parse(url)
const intent = new Intent(Intent.ACTION_VIEW, uri)
return intent.resolveActivity(context.packageManager) != null ? true : false
} else {
return false
}
}
@@ -0,0 +1,21 @@
import { bundleManager, common } from '@kit.AbilityKit';
import OpenLinkOptions from '@ohos.app.ability.OpenLinkOptions'
import { getAbilityContext } from '@dcloudio/uni-runtime'
import { OpenSchema, CanOpenURL } from '../interface.uts'
export const openSchema : OpenSchema = function (url : string) : void {
(getAbilityContext() as common.UIAbilityContext)?.openLink(url, {
appLinkingOnly: false
} as OpenLinkOptions)
}
export const canOpenURL : CanOpenURL = function (url : string) : boolean {
try {
return bundleManager.canOpenLink(url)
} catch (error) {
console.error('[uts-openSchema] url param Error', JSON.stringify(url))
return false
}
}
@@ -0,0 +1,3 @@
{
"deploymentTarget": "12.0"
}
@@ -0,0 +1,22 @@
import { UIApplication } from 'UIKit'
import { URL } from 'Foundation'
import { OpenSchema, CanOpenURL } from '../interface.uts'
export const openSchema : OpenSchema = function (url : string) : void {
if (canOpenURL(url)) {
let uri = new URL(string = url)
UIApplication.shared.open(uri!)
} else {
console.error('[uts-openSchema] url param Error: ', url)
}
}
export const canOpenURL : CanOpenURL = function (url : string) : boolean {
if (typeof url == 'string' && url.length > 0) {
let uri = new URL(string = url)
if (uri != null && UIApplication.shared.canOpenURL(uri!)) {
return true
}
}
return false
}
@@ -0,0 +1,2 @@
export type OpenSchema = (url : string) => void
export type CanOpenURL = (url : string) => boolean
@@ -0,0 +1,12 @@
import { OpenSchema, CanOpenURL } from '../interface.uts'
export const openSchema : OpenSchema = function (url : string) : void {
location.href = url;
}
export const canOpenURL : CanOpenURL = function (url : string) : boolean {
if (url != "") {
return true;
}
return false;
}