Skip to content

Offline when app starts #2

Open

Description

@dgdsouza

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?

Activity

  1. joaomantovani commented on Oct 29, 2024

    @joaomantovani
    Contributor

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

  2. joaomantovani commented on Oct 29, 2024

    @joaomantovani
    Contributor

    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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions