2016-07-05 49 views
0

我使用Sendbird來構建一個使用反應本機的聊天應用程序,但我似乎無法讓它運行。我知道這個應用程序本身有效,因爲我使用了javascript調試器,並且我將信息解析到控制檯,但似乎無法使sendbird.init正常工作。爲了使用反應函數,我需要像sendbird一樣導入方法嗎?如何將函數/文件導入反應原生應用程序?

以下是截圖以供參考:

Login Error: Sendbird not Defined

他們參考,login.js行:41是我叫sendbird.init

編輯:繼承人我的登錄密碼。 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

+0

你用npm安裝了Sendbird嗎? 'NPM安裝sendbird' – Cherniv

+0

是的,它是全球的裝機量,並在node_modules文件夾 –

+0

能否請您添加login.js(尤其是在第41行) – Orlando

回答

0

現在SendBird SDK V3支持最新的React Native,沒有任何問題。

請更新您的SendBird SDK到V3,然後它應該沒問題。

下面是一個示例項目,你可以看看。

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

謝謝!

0

在你的文件的開頭添加

var sendbird = require('sendbird'); 

。看一看這個回購案例中的反應原生樣本https://github.com/smilefam/SendBird-JavaScript

+0

我試過這樣做,它說模塊映射有問題。清除緩存,刪除守望者數據,沒有任何工作。我現在要嘗試重建這個項目。 –

+0

仍然沒有工作,「無法解析從模塊.../sendbird/SendBird.min.js:無法找到該模塊在它的模塊圖或任何node_modules目錄」 但如果我嘗試NPM列出它顯示了 –

相關問題