How to use the @react-native-community/async-storage.getItem function in @react-native-community/async-storage

To help you get started, we’ve selected a few @react-native-community/async-storage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lbryio / lbry-android / app / src / page / discover / view.js View on Github external
AsyncStorage.getItem('firstLaunchTime').then(startTime => {
      if (startTime !== null && !isNaN(parseInt(startTime, 10))) {
        // We don't need this value anymore once we've retrieved it
        AsyncStorage.removeItem('firstLaunchTime');

        // We know this is the first app launch because firstLaunchTime is set and it's a valid number
        const start = parseInt(startTime, 10);
        const now = moment().unix();
        const delta = now - start;
        AsyncStorage.getItem('firstLaunchSuspended').then(suspended => {
          AsyncStorage.removeItem('firstLaunchSuspended');
          const appSuspended = suspended === 'true';
          if (NativeModules.Firebase) {
            NativeModules.Firebase.track('first_run_time', {
              total_seconds: delta,
              app_suspended: appSuspended,
            });
          }
        });
      }
    });
github digidem / mapeo-mobile / src / frontend / App.js View on Github external
const loadNavigationState = async () => {
  try {
    const navState = JSON.parse(await AsyncStorage.getItem(NAV_STORE_KEY));
    const didCrashLastOpen = JSON.parse(
      await AsyncStorage.getItem(ERROR_STORE_KEY)
    );
    // Clear error saved state so that navigation persistence happens on next load
    await AsyncStorage.setItem(ERROR_STORE_KEY, JSON.stringify(false));
    // If the app crashed last time, don't restore nav state
    log("DID CRASH?", didCrashLastOpen);
    return didCrashLastOpen ? null : navState;
  } catch (err) {
    log("Error reading navigation and error state", err);
  }
};
github microsoft / appcenter-sdk-react-native / TestApp / app / AttachmentsProvider.js View on Github external
async function getItemFromStorage(key) {
  try {
    return await AsyncStorage.getItem(key);
  } catch (error) {
    console.error(`Error retrieving item with key: ${key}`);
    console.error(error.message);
  }
  return null;
}
github transistorsoft / rn-background-geolocation-demo / src / lib / Authorization.ts View on Github external
async function register(navigation:any):Promise {
  console.log('[TransistorAuth] this device requires reqistration');
  await BackgroundGeolocation.destroyTransistorAuthorizationToken(ENV.TRACKER_HOST);

  let orgname = await AsyncStorage.getItem("orgname");
  let username = await AsyncStorage.getItem("username");
  if (orgname == null || username == null) {
    Util.navigateHome(navigation);
    return {
      accessToken: "DUMMY_TOKEN",
      refreshToken: "DUMMY_TOKEN",
      expires: -1,
      url: ''
    };
  }

  let token:TransistorAuthorizationToken = await BackgroundGeolocation.findOrCreateTransistorAuthorizationToken(orgname, username, ENV.TRACKER_HOST);

  await BackgroundGeolocation.setConfig({
    transistorAuthorizationToken: token
  });
github brandingbrand / flagship / packages / fsapp / src / components / DevMenu.tsx View on Github external
componentWillMount(): void {
    AsyncStorage.getItem('devKeepPage')
      .then(devKeepPage => {
        this.setState({
          devKeepPage: !!devKeepPage
        });
      })
      .catch(e => console.log('cannot get devKeepPage flag from AsyncStorage', e));
  }
github MetaMask / metamask-mobile / app / core / TransactionsNotificationManager.js View on Github external
requestPushNotificationsPermission = async () => {
		const promptCount = await AsyncStorage.getItem('@MetaMask:pushNotificationsPromptCount');
		if (!promptCount || Number(promptCount) < AppConstants.MAX_PUSH_NOTIFICATION_PROMPT_TIMES) {
			PushNotification.checkPermissions(permissions => {
				if (!permissions || !permissions.alert) {
					Alert.alert(
						strings('notifications.prompt_title'),
						strings('notifications.prompt_desc'),
						[
							{
								text: strings('notifications.prompt_cancel'),
								onPress: () => false,
								style: 'default'
							},
							{
								text: strings('notifications.prompt_ok'),
								onPress: () => PushNotification.requestPermissions()
							}
github wendelfreitas / animavita / packages / mobile / src / pages / Login / index.js View on Github external
async function handleLogin() {
    setLoading(true);

    const response = await handleLoginFacebook();

    if (response.error) {
      throwAuthenticationError();
    }

    if (response.user) {
      const { accessToken } = JSON.parse(await AsyncStorage.getItem('@facebook:accessData'));
      await AsyncStorage.setItem('@animavita:facebook_user', JSON.stringify(response.user));

      loginUser({
        variables: { accessToken },
      });
    }
  }
github discourse / DiscourseMobile / js / site_manager.js View on Github external
return new Promise(resolve => {
      if (this.clientId) {
        resolve(this.clientId);
      } else {
        AsyncStorage.getItem("@ClientId").then(clientId => {
          if (clientId && clientId.length > 0) {
            this.clientId = clientId;
            resolve(clientId);
          } else {
            this.clientId = randomBytes(32);
            AsyncStorage.setItem("@ClientId", this.clientId);
            resolve(this.clientId);
          }
        });
      }
    });
  }
github CarGuo / GSYGithubAPP / app / net / index.js View on Github external
async getAuthorization() {
        let token = await AsyncStorage.getItem(Constant.TOKEN_KEY);
        if (!token) {
            let basic = await AsyncStorage.getItem(Constant.USER_BASIC_CODE);
            if (!basic) {
                //提示输入账号密码
            } else {
                //通过 basic 去获取token,获取到设置,返回token
                return `Basic ${basic}`;
            }
        } else {
            this.optionParams.authorizationCode = token;
            return token;
        }

    }