I have an iphone app that logs data points every time the gps gets a new location point.
I have enabled the "Required background modes" "App registers for location updates" bool in my APP_NAME-info.plist however the background service seams to stop logging, for a reason I cannot associate with anything I am doing other than the device have not been touched for some time. is there something I haven't thought of? I supply my code in case that is at fault.
EDIT I am constantly moving while testing so the gps should be updating.
any pointers in the right direction would be very gratefully received.
-(void)locationUpdate:(CLLocation *)location
{
BOOL sc=YES;
if(!sc){
UIAlertView *al=[[UIAlertView alloc]initWithTitle:@"you have not got gps enabled" message:@"if you dont allow us access to the gps the this app cant log anything" delegate:self cancelButtonTitle:@"ok" otherButtonTitles: nil] ;
[al show];
[al release];
}
if (location != nil) {
gpscylces++;
// NSDate* sourceDate = [NSDate date];
//NSTimeZone* timeZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
//NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
//[formatter setTimeZone:timeZone];
//[formatter setDateFormat:@"EEE MMM dd HH:mm:ss zzz yyyy"];
// NSString *strGMTDate = [formatter stringFromDate:sourceDate];
// NSLog(@"date : %@", strGMTDate);
CLLocationCoordinate2D userCoordi = [location coordinate];
NSString *lat = [NSString stringWithFormat:@"%f",userCoordi.latitude];
currLat = userCoordi.latitude;
NSLog(@"lat : %@", lat);
NSString *log = [NSString stringWithFormat:@"%f",userCoordi.longitude];
currLog = userCoordi.longitude;
NSLog(@"log : %@", log);
currAlt=location.altitude;
NSDate *date =[NSDate date];
currTime= [date timeIntervalSince1970];
int t=(int)currTime;
NSLog(@"date : %d", t);
NSString *accuracy = [NSString stringWithFormat:@"%f",location.horizontalAccuracy];
NSLog(@"accuracy : %@", accuracy);
NSString *speed = [NSString stringWithFormat:@"%f",[location speed]];
NSLog(@"speed : %@", speed);
if (currLat==0&&currLog==0) {
gpscylces++;
}
if(location.horizontalAccuracy>100){
NSLog(@"----not accurate enaough");
return;}
if((!staticshooting)|(staticshooting &(gpscylces==3))){
[[G4EMADBModel sharedInstance] openDB];
NSString *strSQL = [NSString stringWithFormat:@"INSERT INTO TRIP_DATA (TRIPID,GMTTIMESTAMP,LATITUDE,LONGITUDE,ALTITUDE,ACCURACY,SPEED, SPECIES, KILLCOUNT) VALUES(%i,%i, %f, %f,%f,%@,%@, NULL, NULL)",currentTripId,t,currLat,currLog,currAlt, accuracy,speed];
if (waitingForGPS) {
startlogbtn.titleLabel.text=@"Stop Logging";
waitingForGPS=NO;
}
if(lastSyncTime+300<currTime)
{
lastSyncTime=currTime;
[self updateLocationToServer];
}
else{NSLog(@"we have synced this last syntime is %f and curtime is %f ",lastSyncTime,currTime);}
NSLog(@"strQuery : %@", strSQL);
if (staticshooting) {[CLController.locMgr stopUpdatingLocation];}
BOOL success=[[G4EMADBModel sharedInstance] executeUpdate:strSQL];
// [formatter autorelease];
if (success) {
NSLog(@"Success");}else{
NSLog(@"database fail");
}
}//static shooting if
}
}
-(void)locationError:(NSError *)error {
NSLog(@"Error : %@", [error description]);
}