Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offline when app starts #2

Open
deelo55 opened this issue Oct 13, 2024 · 2 comments
Open

Offline when app starts #2

deelo55 opened this issue Oct 13, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@deelo55
Copy link

deelo55 commented Oct 13, 2024

Hi,
If the user is offline when the app starts and then later comes online, am I correct that this will not check the app version once the user goes online?

@joaomantovani
Copy link
Contributor

joaomantovani commented Oct 29, 2024

@deelo55 Yes, you’re correct. With this package, this behavior occurs.

Thank you for pointing it out; I’ll add a handler for this situation.

PS: It’s also possible to use the API directly and create your custom force-update flow.

@joaomantovani joaomantovani added the enhancement New feature or request label Oct 29, 2024
@joaomantovani joaomantovani self-assigned this Oct 29, 2024
@joaomantovani
Copy link
Contributor

joaomantovani commented Oct 29, 2024

As a temporary solution, you could handle the offline on your app in two ways:

1. Integrate directly with API and do your flow 100% customized
https://docs.forceupdate.app/#/api-integration

2. Handle the network connection on your app side:

import React, { useState, useEffect } from 'react';
import { View, Text, Platform } from 'react-native';
import NetInfo from '@react-native-community/netinfo';
import DeviceInfo from 'react-native-device-info';
import { ForceUpdate } from 'reactnative-forceupdate';

const App = () => {
  const [isConnected, setIsConnected] = useState<boolean | null>(null);

  useEffect(() => {
    const unsubscribe = NetInfo.addEventListener((state) => {
      setIsConnected(state.isConnected);
    });

    return () => unsubscribe();
  }, []);

  const version = DeviceInfo.getVersion();
  const language = 'en';
  const platform = Platform.OS === 'ios' ? 'IOS' : 'ANDROID';
  const apiKey = 'YOUR_API_KEY_HERE';

  if (isConnected === false) {
    return (
      <View>
        <Text> Your app flow will go here </Text>
      </View>
    );
  }

  return (
    <ForceUpdate
      api_key={apiKey}
      language={language}
      platform={platform}
      version={version}
    >
      <View>
        <Text> Your app flow will go here </Text>
      </View>
    </ForceUpdate>
  );
};

export default App;

I could easily add the handle above on the code, but the component has a premise to be zero dependencies. I'll think a way to implement that behavior on the main package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants