我正在使用ConnectyCube React Native SDK,但进展并不很快。使用它的方法时,我会错误地说它们是未定义的,例如:TypeError: Cannot read property 'createSession' of undefined
。当我console.log ConnectyCube.createSession
时,它会记录:
ƒ createSession(params, callback) {
this.auth.createSession(params, callback);
}
。
我已经阅读过其他文章,使用react-native link connectycube-reactnative
链接了程序包,但仍然存在相同的问题。有人知道怎么了或如何解决?预先感谢。
import ConnectyCube from 'connectycube-reactnative'
import config from './ConnectycubeConfig'
export default function App() {
console.log(ConnectyCube.createSession)
var userCredentials = {login: 'xxxxxxxxx', password: 'xxxxxxxx'};
ConnectyCube.createSession(userCredentials, (error, session) => {
}); // 'TypeError: Cannot read property 'createSession' of undefined'
答案 0 :(得分:1)
我没有专家回应。看到的是存在一个普遍的问题。根据您的错误,它说“ connectyCude”未定义。尝试下面的代码。
import {ConnectyCube} from 'connectycube-reactnative'
import config from './ConnectycubeConfig'
export default function App() {
var cCube = new ConnectyCube();
console.log(cCube.createSession)
var userCredentials = {login: 'xxxxxxxxx', password: 'xxxxxxxx'};
cCube.createSession(userCredentials, (error, session) => {});
}
答案 1 :(得分:1)
请进行设置,并用proceed
session
。
import ConnectyCube from 'connectycube-reactnative'
...
const cbConfig = [
{
appId: 218,
authKey: 'p-cqm2aatn8ZPM3',
authSecret: '3hmGuXN8AHZOgg6',
},
{
debug: { mode: 1 },
},
]
...
componentWillMount() {
ConnectyCube.init(...cbConfig)
ConnectyCube.createSession((failSession, session) => {
if (!failSession, session) {
alert("you can get login")
}
})
}