提交 90bf4e50 编写于 作者: DCloud_iOS_XHY's avatar DCloud_iOS_XHY

提交 iOS 平台uts插件 系统截屏事件

上级 a7cfea73
......@@ -64,7 +64,7 @@
},
{
"path" : "pages/SystemAPI/android/screenlisten",
"path" : "pages/SystemAPI/ScreenListen/screenlisten",
"style" :
{
"navigationBarTitleText": "",
......
......@@ -3,7 +3,7 @@
<page-head title="监听系统截屏" accordion></page-head>
<uni-list>
<uni-list-item @tap="testScreenShotPremission" title="准备截屏监听权限" class="itemButton" :clickable="true"/>
<uni-list-item @tap="testScreenShotPremission" title="准备截屏监听权限(仅Android)" class="itemButton" :clickable="true"/>
<uni-list-item @tap="testScreenShotListen" title="监听截屏事件" class="itemButton" :clickable="true"/>
<uni-list-item @tap="testScreenShotOff" title="关闭截屏监听" class="itemButton" :clickable="true"/>
</uni-list>
......@@ -30,6 +30,13 @@
methods: {
testScreenShotPremission() {
if (uni.getSystemInfoSync().platform == "ios") {
uni.showToast({
icon:"none",
title:'iOS 平台无需请求权限'
})
return;
}
// 请求写入储存的权限
requestPremission();
},
......@@ -37,16 +44,18 @@
var that = this;
onUserCaptureScreen(function(res) {
console.log(res);
that.screenImage = res.image
uni.showToast({
icon:"none",
title:'截屏捕捉成功'
title:'捕获截屏事件'
})
if (uni.getSystemInfoSync().platform == "android") {
that.screenImage = res.image
}
});
// 提示已经开始监听,注意观察
uni.showToast({
icon:"none",
title:'截屏监听已开启,注意观察下方Image组件'
title:'截屏监听已开启'
})
},
testScreenShotOff() {
......
......@@ -9,11 +9,18 @@
</uni-collapse-item>
</uni-collapse>
<uni-collapse>
<uni-collapse-item title="系统事件" :border="false">
<uni-list>
<uni-list-item @tap="gotoScreenListen" title="监听系统截屏" class="itemButton" :clickable="true" link/>
</uni-list>
</uni-collapse-item>
</uni-collapse>
<uni-collapse>
<uni-collapse-item title="android平台" :border="false">
<uni-list>
<uni-list-item @tap="testGotoDemoActivity" title="自定义activity(需自定义基座)" class="itemButton" :clickable="true" link/>
<uni-list-item @tap="gotoScreenListen" title="监听系统截屏" class="itemButton" :clickable="true" link/>
</uni-list>
</uni-collapse-item>
</uni-collapse>
......@@ -46,7 +53,7 @@
},
gotoScreenListen(){
uni.navigateTo({
url:'/pages/SystemAPI/android/screenlisten'
url:'/pages/SystemAPI/ScreenListen/screenlisten'
})
},
......
// 引用 iOS 原生平台 api
import { UIDevice } from "UIKit";
/**
* 定义 接口参数
*/
type GetBatteryInfoOptions = {
success?: (res: UTSJSONObject) => void;
fail?: (res: UTSJSONObject) => void;
complete?: (res: UTSJSONObject) => void;
};
/**
* 导出 获取电量方法
*/
export default function getBatteryInfo(options: GetBatteryInfoOptions) {
// 开启电量检测
UIDevice.current.isBatteryMonitoringEnabled = true
// 返回数据
const res = {
errMsg: "getBatteryInfo:ok",
level: Number(UIDevice.current.batteryLevel * 100),
......
import { NotificationCenter} from 'Foundation';
import { UIApplication } from "UIKit"
/**
* 定义监听截屏事件工具类
*/
class CaptureScreenTool {
static listener?: UTSCallback;
// 监听截屏
static listenCaptureScreen(callback?: UTSCallback) {
this.listener = callback
// 注册监听截屏事件及回调方法
// target-action 回调方法需要通过 Selector("方法名") 构建
const method = Selector("userDidTakeScreenshot")
NotificationCenter.default.addObserver(this, selector = method, name = UIApplication.userDidTakeScreenshotNotification, object = null)
}
// 捕获截屏回调的方法
// target-action 的方法前需要添加 @objc 前缀
@objc static userDidTakeScreenshot() {
const obj = new UTSJSONObject()
// 回调
this.listener?.(obj)
}
// 移除监听事件
static removeListen(callback?: UTSCallback) {
this.listener = null
NotificationCenter.default.removeObserver(this)
const obj = new UTSJSONObject()
callback?.(obj)
}
}
/**
* 开启截图监听
*/
export function onUserCaptureScreen(callback?: UTSCallback) {
CaptureScreenTool.listenCaptureScreen(callback)
}
/**
* 关闭截屏监听
*/
export function offUserCaptureScreen(callback?: UTSCallback) {
CaptureScreenTool.removeListen(callback)
}
# uts-tencentgeolocation腾讯定位插件使用文档
## Android 平台
1. 申请腾讯地图key
[申请网址](https://lbs.qq.com/mobile/androidMapSDK/developerGuide/getKey)
......@@ -17,7 +19,32 @@
注意打包自定义基座后将androix-core-1.0.0.jar移回原位,然后真机运行自定义基座。这个临时的移出移入问题后续会升级解决,详见uts插件开发文档的[临时注意](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#tempnotice)
## iOS 平台
1.申请腾讯地图key
[申请网址](https://lbs.qq.com/mobile/androidMapSDK/developerGuide/getKey)
2.配置key到插件中
将申请的key配置到插件目录下 app-ios -> info.plist 中 TencentLBSAPIKey 对应的值
```xml
<key>TencentLBSAPIKey</key>
<string>您申请的Key</string>
```
3.配置访问位置权限描述信息
选中工程中的 manifest.json -> App权限配置 -> iOS隐私信息访问的许可描述,分别配置下列权限描述信息
- NSLocationAlwaysUsageDescription
- NSLocationWhenInUseUsageDescription
- NSLocationAlwaysAndWhenInUseUsageDescription
4.制作自定义基座运行后生效
## 相关开发文档
- [UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
- [UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
- [UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
\ No newline at end of file
......@@ -2,15 +2,7 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSLocationAlwaysUsageDescription</key>
<string>访问位置权限</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>使用期间获取位置权限</string>
<key>TencentLBSAPIKey</key>
<string>LZTBZ-77PCJ-HJAFN-KWXJ2-H357V-DJBK4</string>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
<string>您申请的Key</string>
</dict>
</plist>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册