Closed farzansalimian closed 6 years ago
Hi, Did you follow installation guides? and did you run react link?
react-native link
This error is occur when chabok sdk cannot require react-native-device-info
module.
so please make sure npm install chabokpush-rn
and dependencies are successful.
after that run react-native link
so modules can load properly.
@amir-yaghoobi thanx it fix the error but another one showed up
@farzansalimian please replace
const chabok = new chabokpush.Chabok(auth, config)
with:
const chabok = new chabokpush(auth, config)
That way of initializing is for our javascript sdk and not for react native. we will update our documentation.
@amir-yaghoobi i changed it but it does not fix the error
Send your code snippet hear @farzansalimian
@behrad
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';
//import Pushe from 'react-native-pushe'
import LoginScreen from "./screens/login/index";
import SignupScreen from "./screens/signup/index";
import Activate from "./screens/activate/index";
import DrawerHomeScreenRouter from "./src/index.js";
import SideBar from "./src/SideBar/SideBar.js";
import { I18nManager } from 'react-native';
import RNRestart from 'react-native-restart';
var chabokpush = require('chabokpush-rn');
const auth = {
appId: '***',
apiKey: '***',
username: '***',
password: '***',
devMode:true
}
const options = {
silent: false,
realtime: true
};
const chabok = new chabokpush.Chabok(auth, options)
import { StackNavigator, SwitchNavigator, DrawerNavigator } from "react-navigation";
const AppStack = DrawerNavigator({
drawer1: {
screen: DrawerHomeScreenRouter,
}
},
{
headerMode: 'none',
navigationOptions: {
headerVisible: false,
},
drawerPosition: 'right',
contentComponent: props => <SideBar {...props} />
});
const AuthStack = StackNavigator(
{
Login: LoginScreen,
Signup: SignupScreen,
Activate: Activate
},
{
headerMode: 'none',
navigationOptions: {
headerVisible: false,
},
drawerPosition: 'right',
}
);
const HomeScreenRouter = SwitchNavigator(
{
App: AppStack,
Auth: AuthStack,
},
{
headerMode: 'none',
navigationOptions: {
headerVisible: false,
},
initialRouteName: 'Auth',
}
);
export default class App extends Component {
constructor(props) {
super(props);
I18nManager.forceRTL(true);
if (!I18nManager.isRTL) {
RNRestart.Restart();
}
//Pushe.initialize(true);
this.chabok.setPushNotificationToken("TOKEN")
chabok.register('USER_ID')
}
render() {
return (
<HomeScreenRouter />
);
}
}
It's seems you have to install react-native-device-info
as your dependency in order to chabok sdk can work properly. so after all above steps, run:
npm install --save react-native-device-info
Then run react-native link, so chabok can use this dependency
react-native link react-native-device-info
and for initializing chabok:
const chabok = new chabokpush(auth, options)
@amir-yaghoobi i have already installed and linked react-native-device-info but i did it again.i still get the same error
After linking you have to reinstall app. (reloading js bundle does not affect)
react-native run-android
// or
react-native run-ios
I just created a fresh react-native app with react-native init sample
, then i configured android as documents said (added permission and receiver in androidManifest.xml
),
then:
npm install
npm install chabokpush-rn --save
npm install react-native-device-info --save
react-native link chabokpush-rn
react-native link react-native-device-info
In App.js
I added these lines:
import chabokpush from 'chabokpush-rn'
const auth = {
appId: 'APP_ID',
apiKey: 'API_KEY',
username: 'USERNAME',
password: 'PASSWORD',
devMode:true
}
const options = {
silent: false,
realtime: true
};
const chabok = new chabokpush(auth, options)
chabok.register('USER_ID')
in the end react-native run-android
. and app started without any errors
I hope this helps you
@amir-yaghoobi reinstalling chabokpush-rn solve the problem thanks
Your welcome, since this problem is solved, I am going to close this issue
Please update docs if needed @amir-yaghoobi
Hey there, i followed the document but when i try to run the app this error show up