Problem on iOS first run


#1

Hi,
made an application that is getting JSON files from the local network on the setInterval timers. When I RUN it for first time CPU starts to rise from 0-100 %, and when it hits more than 100%, it starts to make my application unusable and requires me to do a new installation. But if I RUN app then close it entirely(not just suspending and then resuming) then turn application back on CPU will never go over 45%. I’m making sure that I clear all intervals when they are not in use and that I don’t run some intervals multiple times.

code is
in home-page.js

“use strict”;
const frameModule = require(‘ui/frame’);
const tabViewModule = require(‘ui/tab-view’);
const app = require(‘application’);

const HomeViewModel = require(’./home-view-model’);
let homeViewModel = new HomeViewModel();

function pageLoaded(args) {

var page = args.object;

page.bindingContext = homeViewModel;
homeViewModel.wifiCheck();

app.on(app.suspendEvent, (args) => {
homeViewModel.stop(); //clears interval timer.clearInterval(this.wifiCheckId);
});
}

and in home-view-model.js

“use strict”;
const geoLocation = require(‘nativescript-geolocation’);
const http = require(‘http’);
const timer = require(‘timer’);
const sound = require(‘nativescript-sound’);
const progressModule = require(‘ui/progress’);
const bluetooth = require(‘nativescript-bluetooth’);
const ts = require(‘nativescript-texttospeech’);

let observableModule = require(‘data/observable’);

function HomeViewModel() {

let viewModel = observableModule.fromObject({

//Statues




connectionType: false,
connectionTypeString: 'Connect to WiFi',
// WiFi
wifiCheckId: false,
wifiCheck: function () {
  this.wifiCheckId = timer.setInterval(() => { 
        http.getJSON('http://192.168.0.1/api/system/terminal_info').then((res) => {
          if(res.board_type){
            this.connectionTypeString = `Connected to ${res.board_type}`;
        }
      },200);
    },

#2

From the looks of the code you are hitting that endpoint every 200 ms. That hardly seems like enough time to execute so you may be stacking up a ridiculous number of requests on the device?