私のロケーションアプリケーションでは、didUpdateToLocation
メソッドを実装しました。このメソッドは毎秒呼び出され、位置データを提供します。しかし、毎秒場所を取得する必要はありません。このメソッドを 5 分ごとに起動する必要があります。これを行うことは可能ですか?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//initialize location lisetener on Application startup
self.myLocationManager = [[CLLocationManager alloc]init];
self.myLocationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.myLocationManager.delegate = self;
[self.myLocationManager startUpdatingLocation];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
self.viewController = [[INNOViewController alloc] initWithNibName:@"INNOViewController_iPhone" bundle:nil];
} else {
self.viewController = [[INNOViewController alloc] initWithNibName:@"INNOViewController_iPad" bundle:nil];
}
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
/*
if(self.executingInBackground)
{
NSLog(@"Aplication running in background");
}
else
{
NSLog(@"Aplication NOT running in background");
}
*/
//NSLog(@"new location->%@ and old location -> %@",newLocation,oldLocation);
NSString *urlAsString = @"http://www.apple.com";
NSURL *url=[NSURL URLWithString:urlAsString];
NSURLRequest *urlRequest=[NSURLRequest requestWithURL:url];
NSOperationQueue *queue = [[NSOperationQueue alloc]init];
[NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if ([data length] > 0 && error == nil) {
NSString *html = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Downloaded html -> %@",html);
//NSLog(@"Downloaded successfully");
}
else if([data length] == 0 && error == nil)
{
NSLog(@"Nothing downloaded");
}
else
{
NSLog(@"Error occured -> %@",error);
}
}];
}