Reputation: 3737
I need to develop an app that could detect if its connected to a certain Access Point. To make sure it is connected to my AP, I need to do an HTTP GET in the background and when the authentication is fetched, notify (local notif.) the user. Can I implement this using NSURLSession running in the background?
Upvotes: 1
Views: 511
Reputation: 18333
Yes. Here is an example:
NSURL *URL = [NSURL URLWithString:@"http://example.com"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
request.HTTPMethod = @"GET";
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error) {
// ... Do notification
}];
[task resume];
Upvotes: 2