现在拼多多、美团、淘宝都搞现金活动,邀请用户一起面对面摇一摇就能分享红包,红包达到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%
- threejs如何做个三维搭积木的游戏?
- three如何实现标记多个起始路过地点位置后选择旅行工具(飞机汽车高铁等),最后三维模拟行驶动画导出mp4?
- ai实时驱动的3d数字人可视频聊天的开源技术有吗
- swoole+phpfpm如何实现不同域名指向不同目录的多租户模式?
- 如何用go替换nginx实现请求phpfpm解析运行php脚本?
- 有没有浏览器离线运行进行各种文档、图片、视频格式转换的开源工具?
- 如何使用go语言搭建一个web防火墙?
- linux如何检测特定网络协议比如http协议中报文是否包含特点关键词并阻止返回给客户?
- 如果在nginx外过滤包含某些关键词的网页并阻止打开?
- 程序员怎么做副业赚钱?



 
				 
			 
			 
				 
			