Problem on iOS first run


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;

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({


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


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?