checking the status of a website from an application
checking the status of a website from an application
- Subject: checking the status of a website from an application
- From: Peter Browne <email@hidden>
- Date: Thu, 23 Dec 2004 23:31:21 +0000
Hi, I have an app that periodically looks up a .plist file on a website I have and creates an NSDictionary from the information in the file...simple enough. However, I want it to be able to use the result of the dictionaryWithContentsOfURL: to check whether the website is still online or not. If the website is unreachable the
first time it is checked, then it registers as not working (no dictionary is made) and follows the relevent code I wrote. If the website is online then the dictionary is initialised with the contents of the URL, but if there is a change of state and the site goes down after a while (or goes back up if it was down to begin with) then the program hangs. Any ideas? Here is the relevent code:
@interface OSBcontroller : NSObject
{
IBOutlet NSTabView *MFDtabView;
NSSpeechSynthesizer *synth;
NSString *ModeID;
NSTimer *SiteCheck;
NSDictionary *radioCheck;
NSNotificationCenter *IDcenter;
}
- (void)awakeFromNib
{
...
...
SiteCheck = [[NSTimer scheduledTimerWithTimeInterval:30 // a 30 second time interval
target:self // Target is this object
selector:@selector(ranSiteCheck:)
userInfo:nil repeats:YES] // No userinfo / repeat infinitely
retain];
...
...
}
- (id)sender
{
if (radioCheck) { radioCheck = nil; NSLog(@"radioCheck now set to %@", radioCheck); } // If the dictionary was already in existence (from last check of the site) then remove its contents
radioCheck = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:@"http://www.noopaala.com/stuff/famcatsInfo.xml"]]; // Create the dictionary
if (!radioCheck) { // If we cannot establish comms with the website...
NSLog(@"Something terrible has happened... Communication with the website has been interrupted");
}
else {
NSString *result = [radioCheck valueForKey:@"areWeAlive"];
if ([result isEqualToString:@"yes we are"]) // After Initialising a dictionary with the contents of a file located on the noopaala server, checks to see if it is equal to a known value
{ // If it is, we can assume the information was correctly received from the server, if it isn't, we can assume the server / we are offline
NSLog(@"Site is online. Initialised dictionary %@", radioCheck);
NSSound *sonarPing = [NSSound soundNamed:@"Submarine"];
[sonarPing play];
[sonarPing release];
}
}
} _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden