Search code examples
react-nativechartsios-simulatorreact-native-chart-kit

What can make a functionality run a simulator and not on the device?


I'm building an app using React Native. I'm fetching an array of values fetched from a database in order to provide users a line chart which refresh every X seconds ( 3s atm ). This works fine on iOS simulator but when it comes to deploy to TestFlight, and run the app on a device, the curves are not displayed, nothing happens. Since I can use some other feature that requires to fetch data from the DB, I figured out that the issue was not from the API requests. I currently use react-native-chart-kit, but I tried with react-native-svg-charts as well, the issue remains the same.

Any hint ?

The issue is the same when I display the array of the fetched values, a new value appears on the simulator every 3 seconds but it does not show anything on the device.


Solution

  • I finally found the issue.

    The issue were spotted at the API request. My request takes 2 timestamp params : start time / end time

    I always debug the app using the browser and launch ios sim from the RN project.

    This time I tried to Run a the project from Xcode and edit the Scheme as release instead of debug .

    When I checked the console from Xcode I noticed that my Start time timestamp when considered as 'NaN'.. Not the End time timestamp.

    Back to the RN project and to the browser console, the timestamp is alright.

    I made some random changes and now it works fine .

    Here's what I had before solving the issue:

    function formatDate(rawStamp) {
            const now = new Date(rawStamp);
            var convertToStr =
                now.getFullYear() +
                "-" +
                ("00" + (now.getMonth() + 1)).slice(-2) +
                "-" +
                ("00" + now.getDate()).slice(-2) +
                " " +
                ("00" + now.getHours()).slice(-2) +
                ":" +
                ("00" + now.getMinutes()).slice(-2) +
                ":" +
                ("00" + now.getSeconds()).slice(-2);
    
       
               return convertToStr
       }
    
       const nowStr = formatDate(Date.now() - 7200000) 
       const gameStampMinusX = Date.parse(nowStr) - (300000) 
       const gameStampMinusXToStr = formatDate(gameStampMinusX)
    

    Here's what solved the issue:

       const nowStr = formatDate(Date.now() - 7200000)
       const gameStampMinusX = Date.now() - 7200000 - 300000
       const gameStampMinusXToStr = formatDate(gameStampMinusX)
    

    I'm a newbie so I cannot explain this behavior, but seems that this little change makes Xcode recognize the timestamp, and proceed the the API request correctly.

    If anyone can explain, feel free !