NimbleKit - fast iOS app development

NKFileDownloader question...

Problem discussions

NKFileDownloader question...

Postby paulsr » Thu Jun 07, 2012 8:38 am

Could someone kindly help me find the stupid mistake in the following piece of code...

Code: Select all
                var getlogo=new NKFileDownloader();
                getlogo.openURL("http://192.168.0.222/airnewspix/cx.png");
                getlogo.start("cx.png");
                setTimeout(getlogoProgress, 1000);

                function getlogoProgress()
                {
                    var progress = getlogo.getProgress();
                    if(progress == -1)
                    {
                        NKLog("failed");
                    }
                    else
                    {
                        NKLog("progress="+progress);
                        if(getlogo.getProgress() < 100)
                        {
                            setTimeout(getlogoProgress, 1000)
                        }
                    }
                }

                NKLog("downloaded");


It's almost identical to the example in the NK documentation. But...

What I see _first_ in the log is "downloaded" followed by an infinite stream of "progress=0" messages.

I also get a file in Documents called cx.png, sometimes empty, sometimes not, but never the complete file. The file on the server does exist. If I rename/remove it, I correctly see "failed" in the log.

Tkx in advance...

--paul
paulsr
 
Posts: 19
Joined: Wed Apr 18, 2012 6:16 am

Re: NKFileDownloader question...

Postby francisco » Thu Jun 07, 2012 9:06 am

Hi paulsr,

If the size of file is very short, the timeout set to 1000 ms haven't time to update progress indicator.
Try with this:

Code: Select all
var getlogo=new NKFileDownloader();
getlogo.openURL("http://192.168.0.222/airnewspix/cx.png");
getlogo.start("cx.png");
getlogoProgress();

function getlogoProgress() {
  var progress = getlogo.getProgress();

  if (progress == -1) {
    NKLog("failed");
  } else {
    NKLog("progress=" + progress);

    if (getlogo.getProgress() < 100) {
      setTimeout(function() {getlogoProgress();}, 100);
    }
  }

  if (progress == 100) {
    NKLog("downloaded");
  }
}


Regards.
Francisco.
User avatar
francisco
NimbleKit Guru
 
Posts: 163
Joined: Thu Dec 01, 2011 12:45 pm
Location: Barcelona, Spain

Re: NKFileDownloader question...

Postby paulsr » Thu Jun 07, 2012 9:22 am

Thanks Francisco ... I never thought of that! Yes, the file is only 7901 bytes.

Will try your solution now...

--paul
paulsr
 
Posts: 19
Joined: Wed Apr 18, 2012 6:16 am

Re: NKFileDownloader question...

Postby paulsr » Thu Jun 07, 2012 10:19 am

Problem solved. Many thanks.

--paul
paulsr
 
Posts: 19
Joined: Wed Apr 18, 2012 6:16 am

Re: NKFileDownloader question...

Postby francisco » Thu Jun 07, 2012 10:45 am

Hi paulsr,

I happy to hear.

Regards.
Francisco.
User avatar
francisco
NimbleKit Guru
 
Posts: 163
Joined: Thu Dec 01, 2011 12:45 pm
Location: Barcelona, Spain


Return to Troubleshooting

Who is online

Users browsing this forum: Google [Bot] and 2 guests