我有一个 iphone 应用程序,每次 gps 获取新位置点时都会记录数据点。
我在我的 APP_NAME-info.plist 中启用了“必需的后台模式”“应用程序注册位置更新”布尔值,但是后台服务接缝停止记录,原因是我无法与我正在做的任何事情相关联,除了设备没有被感动了一段时间。有什么我没有想到的吗?我提供我的代码以防万一。
编辑我在测试时不断移动,因此 gps 应该会更新。
任何指向正确方向的指示都将不胜感激。
-(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]);
}