gpt4 book ai didi

ios - 在 react native 应用程序中未达到 Pubnub 历史回调

转载 作者:行者123 更新时间:2023-11-29 00:38:41 26 4
gpt4 key购买 nike

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

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 .您的回调 需要是一个单独的参数:

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

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

关于ios - 在 react native 应用程序中未达到 Pubnub 历史回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40007788/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com