Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Steps to get this implemented are as follows: </p> <ol> <li><p>Add "App registers for location updates" at item 0 in "Required background modes" in info.plist of your project.</p></li> <li><p>Write below code at application did finish launching.</p> <pre><code>[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startFetchingLocationsContinously) name:START_FETCH_LOCATION object:nil]; </code></pre></li> <li><p>Write below code from where you want to start tracking</p> <pre><code>[[NSNotificationCenter defaultCenter] postNotificationName:START_FETCH_LOCATION object:nil]; AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; [appDelegate startUpdatingDataBase]; </code></pre></li> <li><p>Paste following code to AppDelegate.m</p> <pre><code>#pragma mark - Location Update -(void)startFetchingLocationsContinously{ NSLog(@"start Fetching Locations"); self.locationUtil = [[LocationUtil alloc] init]; [self.locationUtil setDelegate:self]; [self.locationUtil startLocationManager]; } -(void)locationRecievedSuccesfullyWithNewLocation:(CLLocation*)newLocation oldLocation:(CLLocation*)oldLocation{ NSLog(@"location received successfullly in app delegate for Laitude: %f and Longitude:%f, and Altitude:%f, and Vertical Accuracy: %f",newLocation.coordinate.latitude,newLocation.coordinate.longitude,newLocation.altitude,newLocation.verticalAccuracy); } -(void)startUpdatingDataBase{ UIApplication* app = [UIApplication sharedApplication]; bgTask = UIBackgroundTaskInvalid; bgTask = [app beginBackgroundTaskWithExpirationHandler:^(void){ [app endBackgroundTask:bgTask]; }]; SAVE_LOCATION_TIMER = [NSTimer scheduledTimerWithTimeInterval:300 target:self selector:@selector(startFetchingLocationsContinously) userInfo:nil repeats:YES]; } </code></pre></li> <li><p>Add a class by name "LocationUtil" and paste following code into the header file:</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; #import &lt;CoreLocation/CoreLocation.h&gt; @protocol LocationRecievedSuccessfully &lt;NSObject&gt; @optional -(void)locationRecievedSuccesfullyWithNewLocation:(CLLocation*)newLocation oldLocation:(CLLocation*)oldLocation; -(void)addressParsedSuccessfully:(id)address; @end @interface LocationUtil : NSObject &lt;CLLocationManagerDelegate&gt; { } //Properties @property (nonatomic,strong) id&lt;LocationRecievedSuccessfully&gt; delegate; -(void)startLocationManager; </code></pre> <p>And paste following code in LocationUtil.m</p> <pre><code>-(void)startLocationManager{ locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; [locationManager setPausesLocationUpdatesAutomatically:YES]; //Utkarsh 20sep2013 //[locationManager setActivityType:CLActivityTypeFitness]; locationManager.distanceFilter = kCLDistanceFilterNone; locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation; [locationManager startUpdatingLocation]; //Reverse Geocoding. geoCoder=[[CLGeocoder alloc] init]; //set default values for reverse geo coding. } //for iOS&lt;6 - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { //call delegate Method [delegate locationRecievedSuccesfullyWithNewLocation:newLocation oldLocation:oldLocation]; NSLog(@"did Update Location"); } //for iOS&gt;=6. - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { CLLocation *newLocation = [locations objectAtIndex:0]; CLLocation *oldLocation = [locations objectAtIndex:0]; [delegate locationRecievedSuccesfullyWithNewLocation:newLocation oldLocation:oldLocation]; NSLog(@"did Update Locationsssssss"); } </code></pre></li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload