我正在使用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>
)
}
}
答案 0 :(得分:1)
您正在使用我们的v4 JavaScript SDK。您的pubnub.history(
{
channel: channel,
count: 50
},
function (status, response) {
console.log(status, response);
}
);
需要是一个单独的参数:
def brand = json.store.bicycle.brand
这是v4中的细微变化,您可以查看v3 to v4 migration guide进行其他细微更改。