dictionaryWithContentsOfURL Questons

  • Hello all. I am using dictionaryWithContentsOfURL to
    check for new versions of a program  i am working on,
    the problem i am having is that if the user does not
    have an internet connection the check will hang
    forever (or atleast a long period of time). Is there
    an easy way to set a timeout for this function?  Thank
    you for  your time as always.


    _______________________________
    Do you Yahoo!?
    Declare Yourself - Register online to vote today!
    http://vote.yahoo.com
  • The best thing would be to do this in a thread. Here is the code that
    our apps use for this purpose. This normally times out after ten
    seconds in my experience.

    - (IBAction) checkVersion: (id) sender {
        [NSThread detachNewThreadSelector: @selector(checkVersionInThread:)
    toTarget: self withObject: sender];
    }

    - (void) checkVersionInThread: (id) sender {
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

        NSDictionary *versionDict = [NSDictionary
    dictionaryWithContentsOfURL: versionsURL];
        if (versionDict != nil) {
            // do stuff
        } else {
    NSLog(@"Unable to download version information.");
        }

        [pool release];
        [NSThread exit];
    }

    On Oct 18, 2004, at 9:21 PM, Kodex wrote:

    > Hello all. I am using dictionaryWithContentsOfURL to
    > check for new versions of a program  i am working on,
    > the problem i am having is that if the user does not
    > have an internet connection the check will hang
    > forever (or atleast a long period of time). Is there
    > an easy way to set a timeout for this function?  Thank
    > you for  your time as always.
  • You might save yourself some trouble and take a look at
    DTCVersionManager -- http://los.dtcurrie.net/code/

    I think Uli Kusterer also wrote some sort of version management class
    or framework as well.

    -- DTC

    On 2004 Oct 19, at 06:09, Andrew Zamler-Carhart wrote:

    > The best thing would be to do this in a thread. Here is the code that
    > our apps use for this purpose. This normally times out after ten
    > seconds in my experience.
    >
    > - (IBAction) checkVersion: (id) sender {
    > [NSThread detachNewThreadSelector: @selector(checkVersionInThread:)
    > toTarget: self withObject: sender];
    > }
    >
    > - (void) checkVersionInThread: (id) sender {
    > NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    >
    > NSDictionary *versionDict = [NSDictionary
    > dictionaryWithContentsOfURL: versionsURL];
    > if (versionDict != nil) {
    > // do stuff
    > } else {
    > NSLog(@"Unable to download version information.");
    > }
    >
    > [pool release];
    > [NSThread exit];
    > }
    >
    > On Oct 18, 2004, at 9:21 PM, Kodex wrote:
    >
    >> Hello all. I am using dictionaryWithContentsOfURL to
    >> check for new versions of a program  i am working on,
    >> the problem i am having is that if the user does not
    >> have an internet connection the check will hang
    >> forever (or atleast a long period of time). Is there
    >> an easy way to set a timeout for this function?  Thank
    >> you for  your time as always.
    >
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/<d...>
    >
    > This email sent to <d...>
    >
    >