chabokpush / chabok-client-rn-js

Chabok react native wrapper in pure JS (supports code push)
MIT License
4 stars 0 forks source link

can not read property 'appVersion' of undefined #2

Closed farzansalimian closed 6 years ago

farzansalimian commented 6 years ago

Hey there, i followed the document but when i try to run the app this error show up img-20180912-wa0009

amir-yaghoubi commented 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.

farzansalimian commented 6 years ago

@amir-yaghoobi thanx it fix the error but another one showed up screenshot_20180912-204424

amir-yaghoubi commented 6 years ago

@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.

farzansalimian commented 6 years ago

@amir-yaghoobi i changed it but it does not fix the error

screenshot_20180913-025940

behrad commented 6 years ago

Send your code snippet hear @farzansalimian

farzansalimian commented 6 years ago

@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 />
    );
  }
}
amir-yaghoubi commented 6 years ago

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)
farzansalimian commented 6 years ago

@amir-yaghoobi i have already installed and linked react-native-device-info but i did it again.i still get the same error

amir-yaghoubi commented 6 years ago

After linking you have to reinstall app. (reloading js bundle does not affect)

react-native run-android
// or
react-native run-ios
amir-yaghoubi commented 6 years ago

Sample scenario

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

farzansalimian commented 6 years ago

@amir-yaghoobi reinstalling chabokpush-rn solve the problem thanks

amir-yaghoubi commented 6 years ago

Your welcome, since this problem is solved, I am going to close this issue

behrad commented 6 years ago

Please update docs if needed @amir-yaghoobi