如何将函数/文件导入到本机应用程序?

时间:2016-07-05 05:39:55

标签: javascript ios login react-native sendbird

我正在使用Sendbird使用react native构建聊天应用程序,但我似乎无法让它运行。我知道应用程序本身可行,因为我使用了javascript调试器,我正在将我的信息解析到控制台,但我似乎无法让sendbird.init工作。我是否需要像您一样从sendbird导入方法才能使用反应函数?

以下是参考屏幕截图:

Login Error: Sendbird not Defined

他们引用的行,login.js:41是我调用sendbird.init的地方

编辑:继承我的login.js代码(样式表的所有内容)

import React,  { Component } from 'react';
import {
    View,
    Text,
    StyleSheet,
    TextInput,
    TouchableHighlight
} from 'react-native';

var sendbird = require('sendbird');

module.exports = React.createClass({
    getInitialState: function() {
        return {
            username: ''
        };
    },
    render: function() {
        return (
            <View style={styles.container}>
                <View style={styles.loginContainer}>
                    <TextInput
                    style={styles.input}
                    value={this.state.username}
                    onChangeText={(text) => this.setState({username: text})}
                    placeholder={'Enter User Nickname'}
                    maxLength={12}
                    multiline={false}
                    />

                    <TouchableHighlight
                    style={styles.button}
                    underlayColor={'#328FE6'}
                    onPress={this.onPress}
                    >
                        <Text style={styles.label}>LOGIN</Text>
                    </TouchableHighlight>
                </View>
            </View>
        );
    },
    onPress: function() {
        sendbird.init({
            app_id: '879010F5-E064-4D1E-BD15-5956D4A47688',
            guest_id: this.state.username,
            user_name: this.state.username,
            image_url: "",
            access_token: "",
            successFunc: (data) => {
                console.log('success');
            },
            errorFunc: (status, error) => {
                this.setState({username: ''});
            }
        });
    }
});

现在出现的关于映射的错误: New error - tried everything listed here

2 个答案:

答案 0 :(得分:0)

添加

var sendbird = require('sendbird');  

在文件的开头。查看此仓库中的react-native样本,获取示例https://github.com/smilefam/SendBird-JavaScript

答案 1 :(得分:0)

现在,SendBird SDK V3支持最新的React Native,没有任何问题。

请将您的SendBird SDK更新为V3,然后就可以了。

这是您可以查看的示例项目。

https://github.com/smilefam/SendBird-JavaScript

谢谢!