Skip to content

Instantly share code, notes, and snippets.

-(void)load {
NSURL *url = [NSURL URLWithString:@”http://www.mywebsite.com/webService”];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setTimeOutSeconds:10];
}
- (void)requestFinished:(ASIHTTPRequest *)request {
// pull data out of response and act on it
}
- (void)requestFailed:(ASIHTTPRequest *)request {
NSError *error = [request error];
//show an alert view perhaps
}
+ (BOOL)connected
{
Reachability *hostReachability = [Reachability reachabilityForInternetConnection];
NetworkStatus networkStatus = [hostReachability currentReachabilityStatus];
return !(networkStatus == NotReachable);
}
//Called by Reachability whenever status changes.
- (void) reachabilityChanged: (NSNotification* )note
{
Reachability* curReach = [note object];
NSParameterAssert([curReach isKindOfClass: [Reachability class]]);
[self updateInterfaceWithReachability: curReach];
}
// Observe the kNetworkReachabilityChangedNotification. When that
//notification is posted, the method "reachabilityChanged" will be called.
[[NSNotificationCenter defaultCenter] addObserver: self selector:
@selector(reachabilityChanged:)
name: kReachabilityChangedNotification object: nil];
Reachability *hostReachability = [Reachability reachabilityForInternetConnection];
NetworkStatus networkStatus = [hostReachability currentReachabilityStatus];
if (networkStatus == ReachableViaWiFiNetwork)
{
[delegate.queue setMaxConcurrentOperationCount:4];
}
else if (networkStatus == ReachableViaCarrierDataNetwork)
{
[delegate.queue
setMaxConcurrentOperationCount:NSOperationQueueDefaultMaxConcurrentOperationCount];
//receiver chooses appropriate # based on system resources
}
// Setup asynchronous downloading of a resource.
progressView.progress = 0.0;
NSURL *url = [NSURL URLWithString: resourceUrl];
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
[queue setDelegate:self];
[queue setRequestDidFinishSelector:@selector(requestDone:)];
[queue setRequestDidFailSelector:@selector(requestWentWrong:)];
[queue setShowAccurateProgress:YES];
[queue setDownloadProgressDelegate:progressView];
<div class="ui-mobile-viewport ui-panel-left ui-border-right" style="width: 25%; min-width: 250px;"
data-role="panel" data-id="menu" data-hash="crumbs" data-context="a#default">