Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8325685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:31:19+00:00 2026-06-09T00:31:19+00:00

I face an issue where my app requires the users location when they receive

  • 0

I face an issue where my app requires the users location when they receive a push notification while the app is running in the background.

After doing a bit of reading I’m under the impression that this isn’t possible, i.e:

1) App in background

2) Push notification received

3) Get users location and execute block of code.

I found this post on here that suggests you can run a task every N amount of minutes to get the users location. So using this I could check say every ten minutes which would work but it would be a waste of the users battery if I kept activating the GPS. Therefore I was wondering can I tell within my background task if the user has any push notification waiting for my app? That way I would check if they did every ten minutes and only activate the GPS if they did.

Perhaps I’m going about this all the wrong way, I would really appreciate any advice. Sorry for not having any of the code for the background task yet as I’m still trying to get it to work.

[UPDATE]

Thanks Dustin for your advice. After a bit of testing I’ve decided to go with an easier option. I am now using the Apple Significant Location Changes. I store the changes in an array, I’ve set this to only update if the last change was greater than 10min ago. Then when the app becomes active I match the closest time in the array to the time the push notification was sent and use that location.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:31:20+00:00Added an answer on June 9, 2026 at 12:31 am

    As discussed I used alternative solution, here it is:

    Under viewDidLoad or didFinishingLaunchingWithOptions add:

    locationsLogged = [[NSMutableArray alloc] init];
    lastLocationTime = [[NSDate alloc] init]
    locationManager = [[CLLocationManager alloc] init];
    [locationManager setDelegate:self];
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    

    Under applicationDidEnterBackground add:

    [locationManager startMonitoringSignificantLocationChanges];
    

    Add:

    -(void) storeLocations:(CLLocation *)location
    {
    bgTask = [[UIApplication sharedApplication]
              beginBackgroundTaskWithExpirationHandler:
              ^{
                  [[UIApplication sharedApplication] endBackgroundTask:bgTask];
                   }];
    
    [locationsLogged addObject:location];
    
    if (bgTask != UIBackgroundTaskInvalid)
    {
        [[UIApplication sharedApplication] endBackgroundTask:bgTask];
         bgTask = UIBackgroundTaskInvalid;
         }
    }
    
    
     -(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    {
    BOOL isInBackground = NO;
    if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground)
    {
        isInBackground = YES;
    } 
    
    
    NSDate *now = [NSDate date];
    NSTimeInterval diff = [now timeIntervalSinceDate:lastLocationTime];
    
    
    if ((int)diff > 600) {
    
        if (isInBackground)
        {
            [lastLocationTime release];
            lastLocationTime = [[NSDate alloc] init];
            [self storeLocations:newLocation];
        }
        else
        {
            // ...
        }
    }
    }
    

    Then on applicationDidBecomeActive you can use whatever logic you need to apply location information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While running the project on Android emulator,I face the exception as java.lang.NullPointerException at getApplicationContext.Please
When I try to bottom-align text in a DIV element, I face the issue
I have refereed old questions and found that people face many issues after installing
I face issue parsing xhtml with DOCTYPE declaration using DOM parser. Error: java.io.IOException: Server
this get ever more complicated :) now i face another issue in last question
I am new to using intersytems cache and face an issue where I am
I made a application in VB.Net. But some users face crash upon startup. That
I have a client who would like an iphone app that allows users to
Assume I have an ASP.NET MVC app that's not doing anything too fancy (no
Currently I face the following issue - I create a custom ListView ( 1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.