现在拼多多、美团、淘宝都搞现金活动,邀请用户一起面对面摇一摇就能分享红包,红包达到100就可以取现,请问微信小程序或app面对面摇一摇如何实现匹配与邀请?
网友回复
一、微信小程序或app如何检测摇一摇事件
首先我们来实现小程序或app如何实现摇一摇的检测,首先看微信小程序,微信小程序有个api重力感应接口,我们只要监听一下数据就可以检测用户是否摇一摇,代码如下:
Page({
isShow: false,
onShow: function () {
var that = this;
this.isShow = true;
wx.onAccelerometerChange(function (e) {
if(!that.isShow){
return
}
console.log(e.x)
console.log(e.y)
console.log(e.z)
if (e.x > 1 && e.y > 1) {
wx.showToast({
title: '摇一摇成功',
icon: 'success',
duration: 2000
})
}
})
},
onHide: function(){
this.isShow = false;
}
})
好了,那么andriod和ios如何实现呢先看ios如何实现摇一摇检测, 新建一个CWindow类继承UIWindow,重写-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event方法。 .h文件代码:
#import <UIKit/UIKit.h> @interface CWindow : UIWindow @end.m文件代码:
//
// CWindow.m
// Contact
//
#import "CWindow.h"
#import "CConstants.h"
@implementation CWindow
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
//检测摇动
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if(event.type == UIEventSubtypeMotionShake)
{
CCLog(@"Motion shake.");
[[NSNotificationCenter defaultCenter] postNotificationName:APP_SHAKE_NOTIFICATION object:nil];
}
}
/*
// Only override dra...点击查看剩余70%
python能写一个检测nginx rewrite高危漏洞的工具代码?
css如何给video视频进行mask遮罩?
windows如何同时允许两个用户远程桌面连接同一个电脑?
nginx升级到1.30.1导致无法启动 [emerg] SSL_CTX_new() failed怎么办?
什么是ASLR(地址随机化)?
有没有不依赖embedding向量的RAG技术?
有没有支持实时打断语音通话并后台帮你执行任何的ai模型?
开源ai大模型文件格式GGUF、MLX、Safetensors、 ONNX 有什么区别?
出海挣钱支付收款PayPal、Wise 、PingPong、Stripe如何选择?
如何实现类似google的图片隐形水印添加和识别技术?


