Привет, у меня есть задача разработать приложение с помощью Nstimer и фонового процесса.
Я уже реализовал фоновый процесс с таймером. И это работает хорошо. Но у меня проблема, когда я сворачиваю приложение в первый раз, в то время как фоновый процесс не запущен. после сворачивания приложения 3-4 раза. После этого работает ровно. я также отображаю код фоновой задачи и таймера следующим образом.
- (void)applicationDidEnterBackground:(UIApplication *)application {
UIApplication* app = [UIApplication sharedApplication];
NSLog(@"Application enter in background");
[NSTimer scheduledTimerWithTimeInterval:2.0f
target:self
selector:@selector(updateCounter:)
userInfo:nil
repeats:YES];
}
И мой метод updateCounter выглядит следующим образом:
- (void)updateCounter:(NSTimer*)timer {
NSString *id = [[UIDevice currentDevice] uniqueIdentifier];
NSLog(@"uniqueid:%@",id);
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
// Configure the new event with information from the location
CLLocationCoordinate2D coordinate = [location coordinate];
NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];
NSLog(@"dLatitude : %@", latitude);
NSLog(@"dLongitude : %@",longitude);
}
Есть ли у них код, связанный с какой-либо проблемой. Пожалуйста, помогите мне решить эту проблему.
google latitude
иinstagram
. mindsizzlers.com/2011/07/ios-background-location - person Hrushikesh Betai   schedule 17.10.2012