在本机应用程序中未达到 Pubnub 历史回调

Pubnub history callback not reached in react native app

我正在使用 Pubnub 将数据推送和拉取到 React Native 应用程序中,我在其中将数据显示在列表中。由于某种原因,历史回调从未到达,尽管我通过我订阅的频道获取消息。存储和播放已启用。知道这里发生了什么吗?

import React from 'react'
import {
  StyleSheet,
  Text,
  View,
  TouchableHighlight,
  ListView,
} from 'react-native'

import PubNub from 'pubnub';

var username = 'Jenny';
const channel = 'list';

const publish_key = 'XXXXXXXXXXXXXXXXXXXXXXXXX';
const subscribe_key = 'XXXXXXXXXXXXXXXXXXXXXXXXX';

const listSections = ['NOW', 'LATER', 'PROJECTS'];

const pubnub = new PubNub({                         
  publishKey   : publish_key,
  subscribeKey : subscribe_key,
  ssl: true,
  uuid: username
});

export default class MyList extends React.Component{

    constructor(){
        super();
        var ds = new ListView.DataSource({
            getSectionHeaderData: (dataBlob, sectionID) => dataBlob[sectionID],
            getRowData: (dataBlob, sectionID, rowID) => dataBlob[sectionID + ':row' + rowID],
            rowHasChanged: (row1, row2) => row1 !== row2,
            sectionHeaderHasChanged : (s1, s2) => s1 !== s2,
          });
      }
    }


    componentWillMount() {

        this.connect();

        pubnub.addListener({
          message: (m) => this.success([m.message])
        });

        pubnub.subscribe({
          channels: [channel],
        });

    }

    connect() { 
        console.log("connect");

        pubnub.history(
            {
            channel: channel,
            count: 50,
            callback: (response) => {
                console.log(response); 
            }
        );
    }

    success(m){     
      /*Do some data manipulation for the list here */

    }

    render(){

        return(
            <View style={styles.container}>
                <ListView
                    dataSource = {this.state.dataSource}
                    renderRow = {(rowData) => 
                    <View style={styles.rowContainer}>
                        <Text style={styles.rowText}>{rowData}</Text>
                    </View>}
                    renderSectionHeader = {(headerData) => 
                         <Text style={styles.header}>{headerData}</Text>}
                    enableEmptySections = {true}
                />
            </View>
            )
    }
}

您正在使用我们的v4 JavaScript SDK。您的 callback 需要是一个单独的参数:

pubnub.history(
    {
        channel: channel,
        count: 50
    },
    function (status, response) {
        console.log(status, response);
    }
);

这是 v4 中的细微变化,您可以查看 v3 to v4 migration guide 了解其他细微变化。