Author Topic: Running in background (iOS)  (Read 3192 times)

Offline msx

  • Prof. Inline
  • *****
  • Posts: 773
    • View Profile
Running in background (iOS)
« on: 2017-Mar-09 »
Is it possible to get my app running in the background? It is an app that alerts you of speed cameras and it would be very important that it work in the background to use it together with a GPS navigator.  :-[

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4020
    • View Profile
    • Space Fractal
Re: Running in background (iOS)
« Reply #1 on: 2017-Mar-10 »
No, glbasic was never designed for that. It's can crash very very easy on both android and iOS versions. So HIBERNATE must been used.

So hence I'm forced to turn AUTOPLAY to true always.

Same will been happens in Android version to prevent crashes in a future update as well.

Glbasic was not designed for this kind of apps, it's a game language.

However I'm do could call a SUB, while it's in under that command (if its exist) in a update......
« Last Edit: 2017-Mar-10 by spacefractal »
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.

Offline msx

  • Prof. Inline
  • *****
  • Posts: 773
    • View Profile
Re: Running in background (iOS)
« Reply #2 on: 2017-Mar-10 »
I found this.

Code: (glbasic) [Select]
- (void)applicationDidEnterBackground:(UIApplication *)application
{
    UIApplication *app = [UIApplication sharedApplication];
 
    //create new uiBackgroundTask
    __block UIBackgroundTaskIdentifier bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
        [app endBackgroundTask:bgTask];
        bgTask = UIBackgroundTaskInvalid;
    }];
 
    //and create new timer with async call:
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        //run function methodRunAfterBackground
        NSTimer* t = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(methodRunAfterBackground) userInfo:nil repeats:NO];
        [[NSRunLoop currentRunLoop] addTimer:t forMode:NSDefaultRunLoopMode];
        [[NSRunLoop currentRunLoop] run];
    });
}

Is it possible to call GLB_ON_LOOP inside dispatch_async?

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4020
    • View Profile
    • Space Fractal
Re: Running in background (iOS)
« Reply #3 on: 2017-Mar-10 »
im will not recommend to do that and its might simply crash out instead. Im have various crash issues, when its called while its in background.....

So its must being in the HIBERNATE issue to prevent eventuelly crashes. here have been many various issues about that, so im d ont recommend that (since iOS4 me thinks). Im will also do that on Android as well, since im believe all crashes is due the same reason (example when a ads is called).

So im need to take a look on HIBERNATE again to checkout its also doing that correctly on Android too.

When that is fixed, im will add a call in the command to call GLB_ON_HIDE, if the sub exists (for all platforms).....

PS. Im should also check the SOCK commands also fails on Android (which the source code im have, which mightbeen a little bit old, or other fails, or its a iOS exclusive issue). Sadly im are not expert on that area at all.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.

Offline msx

  • Prof. Inline
  • *****
  • Posts: 773
    • View Profile
Re: Running in background (iOS)
« Reply #4 on: 2017-Mar-10 »
Thanks spacefractal.

P.D.: SOCK works perfectly on Android.

Offline spacefractal

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4020
    • View Profile
    • Space Fractal
Re: Running in background (iOS)
« Reply #5 on: 2017-Mar-10 »
im might have a different (and eventuelly a bit older code) source code as you have, which >might< bork on Android as well. Hence im will make sure its not that case. Im will today send all fixes to Gernot as well.

In next version, HIBERNATE will also call GLB_ON_HIDE each 0.5 secs while idle in the command (if the sub exists of course). IM also send that fix to Gernot as well.

Then Gernot need to send me back all code again after that, so we make sure we in sync.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation and The beagle Jam.

Offline msx

  • Prof. Inline
  • *****
  • Posts: 773
    • View Profile
Re: Running in background (iOS)
« Reply #6 on: 2017-Mar-10 »
That's great!!