提交 57bf423c 编写于 作者: D DCloud_LXH

fix: ios 升级中心

上级 a65e789a
......@@ -1175,14 +1175,14 @@
"navigationBarTitleText": "日历"
}
},
// #endif
// #ifdef APP-ANDROID
{
"path": "pages/template/schema/schema",
"style": {
"navigationBarTitleText": "打开schema示例"
}
},
// #endif
// #ifdef APP-ANDROID
{
"path": "pages/template/share/share",
"style": {
......
......@@ -24,7 +24,7 @@
</template>
</uni-collapse>
<!-- #ifdef UNI-APP-X && APP-ANDROID -->
<!-- #ifdef UNI-APP-X -->
<uni-upgrade-center-app ref="upgradePopup" @show="upgradePopupShow" @close="upgradePopupClose" />
<!-- #endif -->
</view>
......@@ -34,7 +34,7 @@
</template>
<script lang="uts">
// #ifdef UNI-APP-X && APP-ANDROID
// #ifdef UNI-APP-X
import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'
// #endif
......@@ -295,7 +295,7 @@
url,
})
}
// #ifdef UNI-APP-X && APP-ANDROID
// #ifdef UNI-APP-X
, upgradePopupShow() {
console.log('upgradePopup show');
if (!this.pageHiden) {
......@@ -309,7 +309,7 @@
// #endif
},
onReady() {
// #ifdef UNI-APP-X && APP-ANDROID
// #ifdef UNI-APP-X
checkUpdate(this.$refs['upgradePopup'] as UniUpgradeCenterAppComponentPublicInstance)
// #endif
},
......
......@@ -186,15 +186,16 @@
open: false,
pages: [] as Page[],
},
// #endif
// #ifdef APP-ANDROID
{
id: 'schema',
url: 'schema',
name: '打开外部链接',
open: false,
pages: [] as Page[],
}, {
}
// #endif
// #ifdef APP-ANDROID
,{
id: 'share',
url: 'share',
name: '分享示例',
......
<template>
<view>
<!-- #ifdef UNI-APP-X -->
<button class="button" @click="openSchema('https://uniapp.dcloud.io/uni-app-x')">使用外部浏览器打开指定URL</button>
<!-- #ifdef APP-ANDROID -->
<button class="button" @click="openSchema('market://details?id=com.tencent.mm')">使用应用商店打开指定App</button>
<button class="button"
@click="openSchema('androidamap://viewMap?sourceApplication=Hello%20uni-app&poiname=DCloud&lat=39.9631018208&lon=116.3406135236&dev=0')">打开地图坐标</button>
<button class="button" @click="openSchema('androidamap://viewMap?sourceApplication=Hello%20uni-app&poiname=DCloud&lat=39.9631018208&lon=116.3406135236&dev=0')">
打开地图坐标
</button>
<!-- #endif -->
<!-- #ifdef APP-IOS -->
<button class="button" @click="openSchema('itms-apps://search.itunes.apple.com//WebObjects//MZSearch.woa/wa/search?media=software&lterm=')">打开 AppStore 到搜索页</button>
<button class="button" @click="openSchema('http://maps.apple.com/?q=Mexican+Restaurant&sll=50.894967,4.341626&z=10&t=s')">打开 iOS 地图坐标</button>
<!-- #endif -->
<!-- #endif -->
</view>
</template>
<script>
import Intent from 'android.content.Intent';
import Uri from 'android.net.Uri';
export default {
data() {
return {
}
},
methods: {
openSchema(url : string) {
const context = UTSAndroid.getUniActivity()!;
const uri = Uri.parse(url)
const intent = new Intent(Intent.ACTION_VIEW, uri)
intent.setData(uri);
context.startActivity(intent);
}
}
}
<script setup lang="uts">
import { openSchema } from '@/uni_modules/uts-openSchema'
</script>
<style>
......
......@@ -22,10 +22,9 @@
</view>
<view class="footer flex-center">
<template v-if="isiOS">
uni-app x 暂不支持 iOS
<!-- <button class="content-button" style="border: none;color: #fff;" plain @click="jumpToAppStore">
<button class="content-button" style="border: none;color: #fff;" plain @click="jumpToAppStore">
{{downLoadBtnTextiOS}}
</button> -->
</button>
</template>
<template v-else>
<template v-if="!downloadSuccess">
......@@ -62,10 +61,10 @@
</template>
<script>
import { openSchema } from '@/uni_modules/uts-openSchema'
import { createNotificationProgress, cancelNotificationProgress, finishNotificationProgress } from '@/uni_modules/uts-progressNotification'
import { type CreateNotificationProgressOptions, type FinishNotificationProgressOptions } from '@/uni_modules/uts-progressNotification/utssdk/interface.uts'
import { UniUpgradeCenterResult, StoreListItem } from '../../utils/call-check-version'
import { openSchema } from '../../utils/utils.uts'
const platform_iOS = 'iOS';
const platform_Android = 'Android';
......@@ -128,6 +127,9 @@
}
},
methods: {
jumpToAppStore() {
openSchema(this.url)
},
show(shown : boolean, localPackageInfo : UniUpgradeCenterResult | null) {
if (localPackageInfo === null) return;
......
......@@ -36,7 +36,8 @@
"uni_modules": {
"dependencies": [
"uni-installApk",
"uts-progressNotification"
"uts-progressNotification",
"uts-openSchema"
],
"encrypt": [],
"platforms": {
......
......@@ -67,7 +67,7 @@ export default function () : Promise<UniUpgradeCenterResult> {
if (typeof appId === 'string' && typeof appVersion === 'string' && appId.length > 0 && appVersion.length > 0) {
let data = {
action: 'checkVersion',
appid: appId,
appid: '__UNI__3584C99',
appVersion: appVersion,
is_uniapp_x: true,
wgtVersion: '0.0.0.0.0.1'
......@@ -77,6 +77,7 @@ export default function () : Promise<UniUpgradeCenterResult> {
name: 'uni-upgrade-center',
data: data
}).then(res => {
console.log('res: ',res);
const code = res.result['code']
const codeIsNumber = ['Int', 'Long', 'number'].includes(typeof code)
if (codeIsNumber) {
......
import Intent from 'android.content.Intent';
import Uri from 'android.net.Uri';
export function openSchema(url : string) : Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
try {
const context = UTSAndroid.getUniActivity()!;
const uri = Uri.parse(url)
const intent = new Intent(Intent.ACTION_VIEW, uri)
intent.setData(uri);
context.startActivity(intent);
resolve(true)
} catch (e) {
reject(e)
}
})
}
## 1.0.0(2024-04-25)
- 更新 在 Android 和 iOS 上打开链接的 UTS API
{
"id": "uts-openSchema",
"displayName": "uts-openSchema",
"version": "1.0.0",
"description": "在 Android 和 iOS 上打开链接的 UTS API",
"keywords": [
"uts-openSchema"
],
"repository": "",
"engines": {
"HBuilderX": "^4.0"
},
"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": "y",
"aliyun": "y",
"alipay": "y"
},
"client": {
"Vue": {
"vue2": "n",
"vue3": "y"
},
"App": {
"app-android": "y",
"app-ios": "y"
},
"H5-mobile": {
"Safari": "n",
"Android Browser": "n",
"微信浏览器(Android)": "n",
"QQ浏览器(Android)": "n"
},
"H5-pc": {
"Chrome": "n",
"IE": "n",
"Edge": "n",
"Firefox": "n",
"Safari": "n"
},
"小程序": {
"微信": "n",
"阿里": "n",
"百度": "n",
"字节跳动": "n",
"QQ": "n",
"钉钉": "n",
"快手": "n",
"飞书": "n",
"京东": "n"
},
"快应用": {
"华为": "n",
"联盟": "n"
}
}
}
}
}
\ No newline at end of file
# uts-openSchema
打开链接,支持:
1. 打开外部 App
2. 使用浏览器打开链接
3. 打开地图到指定地点
4. ...
## 使用
1. 安装此插件
2. 在要使用的地方 `import` 导入
```ts
import { openSchema } 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 打开地图坐标
openSchema('androidamap://viewMap?sourceApplication=Hello%20uni-app&poiname=DCloud&lat=39.9631018208&lon=116.3406135236&dev=0')
// #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)
{
"minSdkVersion": "21"
}
\ No newline at end of file
import Intent from 'android.content.Intent'
import Uri from 'android.net.Uri'
import { OpenSchema } from '../interface.uts'
export const openSchema: OpenSchema = function (url: string) {
if (typeof url === 'string' && url.length > 0) {
const context = UTSAndroid.getUniActivity()!
const uri = Uri.parse(url)
const intent = new Intent(Intent.ACTION_VIEW, uri)
intent.setData(uri)
context.startActivity(intent)
} else {
console.error('url param ERROR:', JSON.stringify(url))
}
}
{
"deploymentTarget": "12.0"
}
\ No newline at end of file
import { OpenSchema } from '../interface.uts'
export const openSchema: OpenSchema = function(url: string): void {
if (typeof url == 'string' && url.length > 0) {
let uri = new URL(string = url)
if (uri != null && UIApplication.shared.canOpenURL(uri!)) {
UIApplication.shared.open(uri!, options = new Map<UIApplication.OpenExternalURLOptionsKey, any>(), completionHandler = null)
}else {
console.error('url param Error: ', url)
}
}else {
console.error('url param Error: ', url)
}
}
\ No newline at end of file
export type OpenSchema = (url: string) => void
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册