2014-11-03 78 views
0

我想在应用程序终止或背景时每10分钟从后台发送位置。 请给代码以及如何使用它.. 这是可能的,如果是,那么建议我 感谢如何在应用程序终止时发送背景位置

+0

你想发送经度和纬度?要么 ? – 2014-11-03 05:30:21

+0

雅经纬度到服务器 – 2014-11-03 05:31:09

+0

请帮我怎么做 – 2014-11-03 05:36:49

回答

0

确保你添加以下到你的头:

@interface ViewController : UIViewController<CLLocationManagerDelegate> 

包括框架:

在导航器中点击您的项目。

点击下的“库链接二进制”

添加Corelocation到项目的加号按钮。

导入头文件

#import <CoreLocation/CoreLocation.h> 

声明CLLocationManager

CLLocationManager *locationManager; 

ViewController.m

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    NSLog(@"today monday"); 
    myTimer = [NSTimer scheduledTimerWithTimeInterval: 60.0 target: self 
              selector: @selector(first:) userInfo: nil repeats: YES]; 
} 

-(void)first:(id)sender 
{ 
    locationManager = [[CLLocationManager alloc] init]; 
    locationManager.delegate = self; 
    locationManager.distanceFilter = kCLDistanceFilterNone; 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    [locationManager startUpdatingLocation]; 
    NSLog(@"called"); 
    [self.view setBackgroundColor:[UIColor greenColor]]; 
    CLLocationCoordinate2D coordinate; 
     NSString * currentLat = [NSString stringWithFormat:@"%f",coordinate.latitude]; 
    NSString * currentLong = [NSString stringWithFormat:@"%f",coordinate.longitude]; 
    NSLog(@"latitude %@",currentLat); 
    NSLog(@"longitude %@",currentLong); 
} 

的NSTimer可以称为以往第一方法1英里n

试试这个,希望对你有所帮助

+0

这段代码将运行时,应用程序在背景或前景..我想在应用程序被终止或终止状态时发送位置 – 2014-11-03 06:54:56

+0

@ShashankPrinceMishra currentLat和currentLong值传递给服务器 – 2014-11-03 07:03:22

相关问题