9

I Have an app on react native. Debug mode works on ios. But Release mode not works. I tried change the optimization level but not helped. The problem that I don't see any error. Just not working some functional. And I can't debug release version of app. How to solve this problem?

As a last change we added following saga, when we remove calling this saga it works

import { select, take, takeLatest, call, put, fork, race } from 'redux-saga/effects';
import R from 'ramda';
import V from 'o-validator';
import * as actionCreators from './actions';
import { redirectTo, showModalError, showModal, showOtp, closeOtp, errorOtp, loader, keychainSet } from '../../../actions/app-actions';
import { storeSession, refreshSession } from '../../../actions/session-actions';
import I18n from 'react-native-i18n';
import {
  KEYCHAIN_RESET,
  KEYCHAIN_GET,
  KEYCHAIN_RESULT
} from '../../../constants/action-types';


import { validatePassword, createCustomError, serverError } from '../../../services/utils';

const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms))


export function * ChangePasswordWatcher( api, action ) {
        yield fork( ChangePasswordFormWatcher, api, action );
}

export function * ChangePasswordFormWatcher(api, action){
  while (true) {
    yield race({
      changePasswordProcess: call(ChangePasswordStart, api),
      cancel: take(['CHANGE_PASSWORD_PASSWORD_RESET'])
    });
    //yield put( loader('hide') );
        yield put( loader('hide') );


  }
}




/**
 * Change Password Sagas starter
 *
 * @param {function} api - api object
 * @param {object} action - action from dispatch
 * @returns
 */
export function * ChangePasswordStart(api, action) {
    try {
            while (true) {
                const { formData } = yield take('CHANGE_PASSWORD_FORM_SUBMIT');
                                let oldPassword = formData.oldPassword;
                                let newPassword = formData.newPassword;
                                let newPasswordConfirmation = formData.newPasswordConfirmation;


                                yield put({
                                type: 'CHANGE_PASSWORD_FORM_VALID'
                              });

                                const validate = validateForm( 'changePasswordForm', formData );
                                if ( validate.valid ) {
                                        yield put( actionCreators.submitChangePasswordFormValid() );
                                        yield put( loader('show') );


                                        let newPasswordResponse = yield call( api.setChangePassword, oldPassword, newPassword);
                    yield put( loader('hide') );
                    if ( !newPasswordResponse.ok ) {

                                            let errors = serverError(newPasswordResponse);
                                            console.log(errors);
                                      console.log('errors newPasswordResponse');

                                      yield put( showModalError({ error: errors }));
                                      yield put( actionCreators.submitNewPasswordFormFailed( errors ) );

                                        //  return false;
                                        }
                                        else {


                                        yield put({
                                            type: KEYCHAIN_GET,
                                            // resultAction: ''
                                        });


                                        const keychain = yield take(KEYCHAIN_RESULT);

                    // Save to Keychain
                                        yield put( keychainSet({
                                            login: keychain.login || false,
                                            password: keychain.password || false
                                        }) );

                            // final screen
                                        yield put( redirectTo('thankyou') );
                                        yield call( delay, 300 );
                                        yield put( actionCreators.changePasswordResetState() );
                                    }

                                }
                                else {
                                    yield put( showModalError({ error: validate.errors }));
                                    yield put( actionCreators.submitChangePasswordFormFailed( validate.errors ));
                                    yield put( actionCreators.changePasswordFailed() );


                    //                      yield put( actionCreators.submitFinFormFailed( ret.errors ) );
                //                      yield put( actionCreators.registrationFailed());
                              }
          // Reset login
         //  yield call( delay, 300 );
        //  yield put( actionCreators.resetState() );

        }

    } catch (e) {
            console.log(e);
    }


}




export function validateForm( formKey, formData ) {
  let
  ret = {
    valid: true,
    errors: false
  },
  schema: {};

  switch ( formKey ) {
    case 'changePasswordForm':
        schema = {
                    oldPassword: V.required( validatePassword ),
                    newPassword: V.required( validatePassword ),
                    newPasswordConfirmation: V.required( R.equals( formData.newPassword ) )
                };
      break;

    default:
      break;
  }

  ret.valid = V.validate( schema, formData );

  if ( !ret.valid ) {
    ret.errors = V.getErrors( schema, formData );
    ret.errors = R.zipObj( R.pluck('property', ret.errors), ret.errors );
  }

  console.log('isValid: ' + ret.valid.toString());

  return ret;
}

To comment all Console.log statements not helped

import { select, take, takeLatest, call, put, fork, race } from 'redux-saga/effects';
import R from 'ramda';
import V from 'o-validator';
import * as actionCreators from './actions';
import { redirectTo, showModalError, showModal, showOtp, closeOtp, errorOtp, loader, keychainSet } from '../../../actions/app-actions';
import { storeSession, refreshSession } from '../../../actions/session-actions';
import I18n from 'react-native-i18n';
import {
  KEYCHAIN_RESET,
  KEYCHAIN_GET,
  KEYCHAIN_RESULT
} from '../../../constants/action-types';


import { validatePassword, createCustomError, serverError } from '../../../services/utils';

const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms))


export function * changePasswordScreenWatcher( api, action ) {
        yield fork( ChangePasswordFormWatcher, api, action );
}

export function * ChangePasswordFormWatcher(api, action){
  while (true) {
    yield race({
      changePasswordProcess: call(ChangePasswordStart, api),
      cancel: take(['CHANGE_PASSWORD_PASSWORD_RESET'])
    });
    //yield put( loader('hide') );
        yield put( loader('hide') );


  }
}




/**
 * Change Password Sagas starter
 *
 * @param {function} api - api object
 * @param {object} action - action from dispatch
 * @returns
 */
export function * ChangePasswordStart(api, action) {
    try {
            while (true) {
                const { formData } = yield take('CHANGE_PASSWORD_FORM_SUBMIT');
                                let oldPassword = formData.oldPassword;
                                let newPassword = formData.newPassword;
                                let newPasswordConfirmation = formData.newPasswordConfirmation;


                                yield put({
                                type: 'CHANGE_PASSWORD_FORM_VALID'
                              });

                                const validate = validateForm( 'changePasswordForm', formData );
                                if ( validate.valid ) {
                                        yield put( actionCreators.submitChangePasswordFormValid() );
                                        yield put( loader('show') );


                                        let newPasswordResponse = yield call( api.setChangePassword, oldPassword, newPassword);
                    yield put( loader('hide') );
                    if ( !newPasswordResponse.ok ) {

                                            let errors = serverError(newPasswordResponse);
                                            //console.log(errors);
                                      //console.log('errors newPasswordResponse');

                                      yield put( showModalError({ error: errors }));
                                      yield put( actionCreators.submitNewPasswordFormFailed( errors ) );

                                        //  return false;
                                        }
                                        else {


                                        yield put({
                                            type: KEYCHAIN_GET,
                                            // resultAction: ''
                                        });


                                        const keychain = yield take(KEYCHAIN_RESULT);

                    // Save to Keychain
                                        yield put( keychainSet({
                                            login: keychain.login || false,
                                            password: keychain.password || false
                                        }) );

                            // final screen
                                        yield put( redirectTo('thankyou') );
                                        yield call( delay, 300 );
                                        yield put( actionCreators.changePasswordResetState() );
                                    }

                                }
                                else {
                                    yield put( showModalError({ error: validate.errors }));
                                    yield put( actionCreators.submitChangePasswordFormFailed( validate.errors ));
                                    yield put( actionCreators.changePasswordFailed() );


                    //                      yield put( actionCreators.submitFinFormFailed( ret.errors ) );
                //                      yield put( actionCreators.registrationFailed());
                              }
          // Reset login
         //  yield call( delay, 300 );
        //  yield put( actionCreators.resetState() );

        }

    } catch (e) {
            //console.log(e);
    }


}




export function validateForm( formKey, formData ) {
  let ret = {
    valid: true,
    errors: false
  };

  switch ( formKey ) {
    case 'changePasswordForm':
        schema = {
                    oldPassword: V.required( validatePassword ),
                    newPassword: V.required( validatePassword ),
                    newPasswordConfirmation: V.required( R.equals( formData.newPassword ) )
                };
      break;

    default:
      break;
  }

  ret.valid = V.validate( schema, formData );

  if ( !ret.valid ) {
    ret.errors = V.getErrors( schema, formData );
    ret.errors = R.zipObj( R.pluck('property', ret.errors), ret.errors );
  }

  //console.log('isValid: ' + ret.valid.toString());

  return ret;
}
Kamil Ibadov
  • 1,436
  • 2
  • 20
  • 44

3 Answers3

0

Based on the information provided, it seems like you're loading different bundles when switching between debug and release modes.

Make sure you configured your app to use a static bundle in Release Mode.

Then your app will render the same bundle in both modes, and the behavior may be as you're expecting.

Luiz Dias
  • 1,947
  • 17
  • 22
0

It has to be a library which is clashing with your iOS version of the app. Try removing libraries one by one and see if it works on each attempt.

A shortcut would be to check the code of the libraries you are using and see if any of the APIs which are being used by the library is deprecated or not.

I came across a similar problem and in my case, it was lottie-animation which was causing the problem. Hope you'll be able to solve it.

atitpatel
  • 3,104
  • 1
  • 24
  • 34
-3

Seems like you do console.log's in your code. Since your real phone environment dosen't have console-global variable make sure you get rid of these before compiling to production release.

EDIT

Previous statement is not entirely true. Even tho I have myself run into edge cases where console.log will crash your app when not running in debugging mode, it seems like this is not always the case and production build would run with them in place. Either way performance increase you might achieve by removing them should be taken in consideration https://facebook.github.io/react-native/docs/performance.html#performance

Jimi Pajala
  • 2,358
  • 11
  • 20
  • 2
    Your fact is wrong. `React Native` have JavascriptCore engine behind the layer, therefore console.log should able to be used even in production. Try it yourself, you'll never be hurted – Alfian Busyro Sep 18 '18 at 04:18
  • Seems like you are right. Only relevant reason for removing them in production would be to achieve performance increase it seems like. https://facebook.github.io/react-native/docs/performance.html#performance – Jimi Pajala Sep 18 '18 at 10:08
  • Well, if you logging a big chunk of data, it would be a performance loss. Therefore use console.log wisely. Moreover, if you're talking about performance, rendering is much important than console.log – Alfian Busyro Sep 19 '18 at 06:14
  • I don't know why people have given this negative points, This worked for me. – Gandalf Dec 28 '19 at 12:51