Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. iOS ~ Backgrounding, Suspend, Inactive
Forum Updated to NodeBB v4.3 + New Features

iOS ~ Backgrounding, Suspend, Inactive

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
12 Posts 3 Posters 4.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SamGrant
    wrote on last edited by
    #1

    When running my app on iOS 9, that is supposed to run in the background, once the app goes to Qt.ApplicationInactive, iOS will stop all processing.
    My app collects the user's location. I have updated the info.plist to account for required background modes and the location services. But, processing still stops.
    On iOS 6.1, however, this does not happen, processing continues when the app is backgrounded.
    Is this caused by the transition from Qt.ApplicationSuspended to Qt.ApplicationInactive?
    How do I get around this?
    --Sam

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SamGrant
      wrote on last edited by
      #2

      According to StackOverflow, we should be using this to enable background locations in iOS 9...but how do we do that with Qt?

      if ([self.locationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) {
      [self.locationManager setAllowsBackgroundLocationUpdates:YES];
      }

      http://stackoverflow.com/questions/32758125/ios9-not-tracking-location-while-in-background

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SamGrant
        wrote on last edited by
        #3

        Ok, Trying to incorporate the Objective-C calls necessary for iOS 9. Here is what I have:

        .h:
        #ifndef _iosLocation_h
        #define _iosLocation_h

        class IOSLocation
        {
        public:
        static void EnableIOSBackgroundLocation();
        };

        #endif

        .mm:
        #include "ioslocation.h"

        void IOSLocation::EnableIOSBackgroundLocation()
        {

        if ([self.locationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) {
        [self.locationManager setAllowsBackgroundLocationUpdates:YES];
        }
        if ([self.locationManager respondsToSelector:@selector(pausesLocationUpdatesAutomatically:)]) {
        [self.locationManager.pausesLocationUpdatesAutomatically:NO];
        }
        }

        And in my main.cpp file, I call "IOSLocation::EnableIOSBackgroundLocation()".

        When compiling, I get an error about 'self'...so what should I be using? Pardon the ignorance, but this is my first attempt at mixing Objective-C and CPP and QT and QML and ... and...

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hamer
          wrote on last edited by hamer
          #4

          To the best of my knowledge Qt pauses the event loop when the app gets into background (which is good with respect to energy saving e.g.). For location tracking you will probably have to use and implement the native NSLocation stuff (at least this is the way I am doing it).

          S 1 Reply Last reply
          0
          • S Offline
            S Offline
            SamGrant
            wrote on last edited by
            #5

            I am doing this, which works in the iOS simulator (iOS 9, iPhone6), but not on the phone.

            I call EnableIOSBackgroundLocation() in my main.cpp file. The return Boolean sets a QML Image to be visible (either a green GPS icon on success or a red one on failure).

            In the simulator, the green GPS icon shows up...and the location continues to be logged when the app is put in the background. However, on a real iPhone 6 running iOS 9, the GPS is killed after a couple of minutes when the app is backgrounded.

            Anyone have any ideas why?

            iosLocation .mm:

            #include "ioslocation.h"

            #import <CoreLocation/CoreLocation.h>

            bool IOSLocation::EnableIOSBackgroundLocation()
            {
            CLLocationManager *locationManager;
            locationManager = [[CLLocationManager alloc] init];

            if ([locationManager respondsToSelector:@selector(allowsBackgroundLocationUpdates:)]) {
            [locationManager setAllowsBackgroundLocationUpdates:YES];
            if ([locationManager respondsToSelector:@selector(pausesLocationUpdatesAutomatically:)]) {
            [locationManager setPausesLocationUpdatesAutomatically:NO];
            return true;
            }
            else
            {
            return false;
            }
            }
            return false;
            }

            iosLocation .h:

            #ifndef _iosLocation_h
            #define _iosLocation_h

            class IOSLocation
            {
            public:
            static void EnableIOSBackgroundLocation();
            };

            #endif

            1 Reply Last reply
            0
            • H hamer

              To the best of my knowledge Qt pauses the event loop when the app gets into background (which is good with respect to energy saving e.g.). For location tracking you will probably have to use and implement the native NSLocation stuff (at least this is the way I am doing it).

              S Offline
              S Offline
              SamGrant
              wrote on last edited by
              #6

              @hamer
              Can you provide an example of how you are doing this?

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SamGrant
                wrote on last edited by SamGrant
                #7

                I've had a thought on what may be happening. Since the locationManager instance is declared inside the EnableIOSBackgroundLocation function, is it possible that it is not persisting beyond that function? And therefore those CLLocationManger values are not remaining after the function exits?

                If that is the case, then how can I create a locationManger variable that persists throughout the application? How can I declare it and access it from the QT code?

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SamGrant
                  wrote on last edited by SamGrant
                  #8

                  Ok, more info...

                  Using this code:
                  *.h

                  #ifndef _iosLocation_h
                  #define _iosLocation_h

                  class IOSLocation
                  {
                  public:
                  static bool EnableIOSBackgroundLocation();
                  };

                  #endif

                  *.mm:
                  #include "ioslocation.h"

                  #import <CoreLocation/CoreLocation.h>

                  bool IOSLocation::EnableIOSBackgroundLocation()
                  {
                  CLLocationManager *myLocMan;
                  myLocMan = [[CLLocationManager alloc] init];

                  if ([myLocMan respondsToSelector:@selector(allowsBackgroundLocat ionUpdates]) {
                  myLocMan.allowsBackgroundLocationUpdates = YES;

                  if ([myLocMan respondsToSelector:@selector(pausesLocationUpdates Automatically]) {
                  myLocMan.pausesLocationUpdatesAutomatically = NO;

                  // Request location authorization
                  [myLocMan requestAlwaysAuthorization];

                  // Set an accuracy level. The higher, the better for energy.
                  myLocMan.desiredAccuracy = kCLLocationAccuracyBest;

                  // Specify the type of activity your app is currently performing
                  myLocMan.activityType = CLActivityTypeOtherNavigation;

                  // Set distance filter to NONE
                  myLocMan.distanceFilter = kCLDistanceFilterNone;

                  return true;
                  } else {
                  return false;
                  }
                  }
                  return false;
                  }

                  And debugging with XCode while running on an attached iPhone... SOME of the variables are set correctly (such as allowsBackgroundLocationUpdates and myLocMan.activityType). However, the other essential pieces do not get set (pausesLocationUpdatesAutomatically, myLocMan.distanceFilter and myLocMan.desiredAccuracy).

                  So, I again did more Googling...and have come up with a possible reason. It seems to be that the 'extra' parameters can only be set IF the delegate of CLLocationManager is set... does that sound right to anyone?

                  Being as that may be the case...how can I set it? I've pulled code from https://github.com/colede/qt-app-delegate, but am not sure exactly how to get the AppDelegate and set it properly.

                  Anyone???

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SamGrant
                    wrote on last edited by
                    #9

                    And...with more searching and headscratching... I see that MANY examples of using CoreLocation set the delegate to 'self'...

                    So that raises the question... How & Where do I get 'self' when compiling this QT project in XCode? I've tried, but I keep getting 'self is undefined'.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Hi,

                      self is the Objective-C version of C++ this

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        SamGrant
                        wrote on last edited by
                        #11

                        So, as indicated by SGaist here, Anda_Skoa over at qtCentre and 'Eskimo' over on the Apple Dev Forum, this is an Objective-C issue.

                        However.. since I am trying to use Objective-C in my QT app, the issue then becomes...How Do I Use Objective-C?

                        In short, the posted code runs without any real issues. Just some of the variables are not getting set as I need them to. Not being an Objective-C (or iOS) guru, I have to ask the noob question... Is the code I posted truly Objective-C? If it is not, then how do I make it Objective-C (so I can get to the 'self' object), and call it from my QT C++ functions?

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          There's one important thing: there's already a CLLocationManager used by the QGeoPositionInfoSource iOS plugin.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved