2012-10-05 3 views
2

GPS 배경 키 때문에 내 앱이 거부 된 것은 두 번째입니다.가이드 라인에 따른 iPhone 앱 거부 2.16

-(void)stopGPS{ 
[self.locationManagerAll stopUpdatingLocation]; 
self.locationManagerAll.delegate = nil; 
locationManagerAll = nil; 
self.cloop = 1; 

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 
[prefs setValue:[NSNumber numberWithBool:NO] forKey:@"UpdateLocation"]; 
[prefs setValue:[NSNumber numberWithInt:0] forKey:@"updationTime"]; 
[prefs synchronize]; 
[set.gpsOnOff setOn:NO]; 
[set.settingsTable reloadData]; 
[self stopThread]; 
} 
-(void)startGPS{ 

if ([CLLocationManager locationServicesEnabled]){ 
    if(self.locationManagerAll == nil){ 
     self.locationManagerAll = [[CLLocationManager alloc] init]; 
     self.locationManagerAll.delegate = self; 
    } 
    self.locationManagerAll.desiredAccuracy = kCLLocationAccuracyHundredMeters; 
    self.locationManagerAll.distanceFilter = kCLDistanceFilterNone; 
    [self.locationManagerAll startUpdatingLocation]; 

}else { 
    [set.gpsOnOff setOn:NO]; 
    [set.settingsTable reloadData]; 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location Service Disabled" 
                message:@"To re-enable, please go to Settings and turn on Location Service for this app." 
                delegate:nil 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; 
} 
} 

시작하거나 GPS 위치를 중지하는 데 사용이 위의 기능, 여기에 GPS 위치에 대한 구현은 다음과 같습니다 : 여기에 내가 사용하고있는 코드는 또한 타이머 스레드를 사용하고

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 
if ([oldLocation.timestamp timeIntervalSinceNow] < - 5) return; 
if (newLocation.horizontalAccuracy > 5.0) return; 
if (newLocation.coordinate.latitude == oldLocation.coordinate.latitude && newLocation.coordinate.longitude == oldLocation.coordinate.longitude) return; 
NSString *currentLatitude = [[NSString alloc] 
          initWithFormat:@"%f", 
          newLocation.coordinate.latitude]; 
NSString *currentLongitude = [[NSString alloc] 
           initWithFormat:@"%f", 
           newLocation.coordinate.longitude]; 
[prefs setValue:currentLatitude forKey:@"UpdateLocationLati"]; 
[prefs setValue:currentLongitude forKey:@"UpdateLocationLongi"]; 
[prefs synchronize]; 
[currentLatitude release]; 
[currentLongitude release]; 
if (self.cloop == 1) { 
    /*UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Current location saved." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; */ 

    self.cloop = 0; 
    [prefs setValue:[NSNumber numberWithInt:60] forKey:@"updationTime"]; 
    [prefs setValue:[NSNumber numberWithBool:YES] forKey:@"UpdateLocation"]; 
    [prefs synchronize]; 
    [set.gpsOnOff setOn:YES]; 
    [set.settingsTable reloadData]; 
    [self startThread]; 
} 
} 
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{ 
if ([error code] != kCLErrorLocationUnknown) { 
    [self stopGPS]; 
    UIAlertView *alert = [[UIAlertView alloc] init]; 
    [alert setTitle:@"Location"]; 
    [alert setMessage:@"Unable to get current location"]; 
    [alert setDelegate:self.set]; 
    [alert addButtonWithTitle:@"Cancel"]; 
    [alert addButtonWithTitle:@"Retry"]; 
    [alert show]; 
    [alert release]; 

} 
} 

매초마다 서버의 위치를 ​​업데이트합니다. 응용 프로그램이 배경에 갔다 타이머 정지 AS 나는이 문제를 처리하기 위해이 코드를 사용하고 있습니다 :

-(void)startThread 
{ 
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 
if ([[prefs objectForKey:@"UpdateLocation"] boolValue]) { 
    self.updateLocation = [[NSThread alloc] initWithTarget:self selector:@selector(setUpTimerThread) object:nil]; 
    [self.updateLocation start]; 
} 
} 
-(void)stopThread{ 
[self.updateLocation cancel]; 
updateLocation = nil; 
[self.gpsTimer invalidate]; 
} 
-(void)setUpTimerThread 
{ 
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 

if ([[prefs objectForKey:@"updationTime"] intValue] > 0) { 
    self.gpsTimer = [NSTimer timerWithTimeInterval:[[prefs objectForKey:@"updationTime"] intValue] target:self selector:@selector(triggerTimer) userInfo:nil repeats:YES]; 
    NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; 
    [runLoop addTimer:gpsTimer forMode:NSRunLoopCommonModes]; 
    [runLoop run]; 
} 
[pool release]; 
} 
-(void)triggerTimer 
{ 
NSLog(@"***Timer Called after seconds**"); 
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 
NSString *location = [[[NSString alloc] initWithFormat:@"%f_%f",[[prefs objectForKey:@"UpdateLocationLati"] doubleValue], [[prefs objectForKey:@"UpdateLocationLongi"] doubleValue]] autorelease]; 
NSString *urlGen = [[[NSString alloc] initWithFormat:@"%@%d/%@",[prefs objectForKey:@"update_user_location"],[[prefs objectForKey:@"USERID"] intValue], location] autorelease]; 
NSLog(@"urlGen: %@", urlGen); 
NSString *rt = [JSONModel stringWithUrl:urlGen]; 
if (self.alertLoop == 1) { 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"GPS location has been sent. This alert message will only prompt you once." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alert show]; 
    [alert release]; 
    self.alertLoop = 0; 
} 
NSLog(@"UPDATE LOCATION : %d", [rt intValue]); 
} 

나는 완전히 혼란 스러워요 :

- (void)applicationDidEnterBackground:(UIApplication *)application{ 
/* 
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.*/ 
if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)]) { //Check if our iOS version supports multitasking I.E iOS 4 
    if ([[UIDevice currentDevice] isMultitaskingSupported]) { //Check if device supports mulitasking 
     UIApplication *application = [UIApplication sharedApplication]; //Get the shared application instance 


     __block UIBackgroundTaskIdentifier background_task; //Create a task object 
     background_task = [application beginBackgroundTaskWithExpirationHandler: ^{ 
      [application endBackgroundTask:background_task]; 
      //Tell the system that we are done with the tasks 
      background_task = UIBackgroundTaskInvalid; //Set the task to be invalid 
      //System will be shutting down the app at any point in time now 
     }]; 
     //Background tasks require you to use asyncrous tasks 
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
      //Perform your tasks that your application requires     
      //I do what i need to do here.... synchronously...     
      NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 
      if ([[prefs objectForKey:@"updationTime"] intValue] > 0 && [[prefs objectForKey:@"UpdateLocation"] boolValue]) { 
       self.backgroundTimer = [NSTimer timerWithTimeInterval:[[prefs objectForKey:@"updationTime"] intValue] target:self selector:@selector(backgroundTriggerTimer) userInfo:nil repeats:YES]; 
       NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; 
       [runLoop addTimer:backgroundTimer forMode:NSRunLoopCommonModes]; 
       [runLoop run]; 
      } 
      [application endBackgroundTask:background_task]; 
      //End the task so the system knows that you are done with what you need to perform 
      background_task = UIBackgroundTaskInvalid; //Invalidate the background_task 
     }); 
    }else if (![[UIDevice currentDevice] isMultitaskingSupported]) { 
     NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 
     if ([[prefs objectForKey:@"UpdateLocation"] boolValue]){ 
      [self stopGPS]; 
     } 
    } 
}else if (![[UIDevice currentDevice] isMultitaskingSupported]) { 
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; 
    if ([[prefs objectForKey:@"UpdateLocation"] boolValue]){ 
     [self stopGPS]; 
    } 
} 
} 

여기 내가 사용하고 스레드 코드입니다. 내가 뭔가를 놓친다면 나는 모른다. 어떤 몸이라도 도와주세요.

답변

5

당신이 놓친 것처럼 보이지 않지만 2.16 거부 이유 중 하나는 iTunesConnect의 앱 메타에 대한 앱 설명에 GPS 배터리 경고가 없다는 것입니다. "GPS를 계속 사용하면 배터리 수명이 단축 될 수 있습니다 "또는 그런 것.

+0

나는 똑같은 문제가있다. 그 설명은 해결책이다. –

+0

나는 앱이 시작될 때이 경고를 포기 선언에 추가했다. iTunesConnect의 앱 메타에 추가해야합니까? – mahoon

+0

예, 반드시 iTunesConnect의 앱 메타에 포함시켜야합니다. 바이너리를 다시 업로드 할 필요가 없습니다. 앱에 코드 수준의 문제가없는 경우 메타를 수정 한 다음 iTC의 해결 센터에 메시지를 보내면됩니다. –