FileSystem2019-06-24 14:11
FileSystem.getInfoAsync(`${FileSystem.documentDirectory}setting.json`)
  .then(res => {
    console.log('Setting.read.fileStatus', res);
    if (res.exists) {

      /* if exists then read and push to state */
      FileSystem.readAsStringAsync(
        `${FileSystem.documentDirectory}setting.json`
        )
      .then(res => JSON.parse(res))
      .then(res => {
        dispatch({
          type: 'SETTING_READ_FINISHED',
          settings: res,
        });
        console.log('Setting.read.Finished', res);
      });

    } else {

      /* if not exists then create new setting file and push default value to state */
      FileSystem.writeAsStringAsync(
        `${FileSystem.documentDirectory}setting.json`,
        JSON.stringify(getState().app.settings)
        ).then(res => {
          dispatch({
            type: 'SETTING_READ_FINISHED',
          });
        });
        /* create a new sub folder */
        FileSystem.makeDirectoryAsync(
          `${FileSystem.documentDirectory}savedScore/`
        );
      }

    })
  .catch(err => {

    dispatch({
      type: 'SETTING_READ_FAILED',
    });
    
  });
Powered by Remix
|
Designed by szhshp
|
Copyright © szhshp 2022