react native + wechat4u 的努力

写在前面的话:本博纯粹是为记录自己的辛路历程,若有缘的你觉得这篇博文中错漏百出,请不要嗤笑,我只是一个兴趣爱好者,而非专业人士,如果留言指正,我当然是非常开心的啦~

2017年1月14日21:29:01

wechat4u模块已经被npm收录,react-native init初始化项目后直接npm install wechat4u --save就能安装到项目目录,同时自动“保存”index.json文件,但是.babelrc文件还得自己配置,wechat4u的.babelrc文件中preset项里面都是latest,项目运行时经常报包含latest的错误,改成“es2015”就不这么报了。

目标要一步一步的来,首先只要实现获得QR的url并显示就行了,这个是我的代码:

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Image,
  Text,
  View
} from 'react-native';

export default class XzlWX extends Component {
  constructor(props) {
    super(props);
    const Wechat = require('wechat4u')
    this.state = {
      bot: new Wechat(),
      qrurl: ''
    };
  }
  componentDidMount() {
    // *
    this.bot.on('error', err => {
      console.log('错误:', err)
    })
    this.bot.on('uuid', uuid => {
      this.state.qrurl = './qrurl.txt','https://login.weixin.qq.com/qrcode/' + uuid;
    })//*/
    this.bot.start()
  }
  render() {
    if (!this.state.qrurl) {
      return (
          <View style={styles.container}>
            <Text style={styles.welcome}>
              waiting for QR...
            </Text>
          </View>
        );
    }
    return (
      <View style={styles.container}>
        <Image
          source={{uri: this.state.qrurl}}
          style={styles.thumbnail}
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
  thumbnail: {
    width: 53,
    height: 81,
  },
});

AppRegistry.registerComponent('XzlWX', () => XzlWX);
这个是错误提示,是因为wechat4u的事件不被react native支持所致?

目前就到这里了,下一步是不是该了解一下wechat4u的事件机制以及react native的事件注册方法呢?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值