mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-18 00:54:19 +00:00
Added an option to execute JUCEApplication's suspend() method on an iOS background task to give you extra time to save your app's state
This commit is contained in:
parent
a839fa24b3
commit
2bec815bb3
2 changed files with 42 additions and 2 deletions
|
|
@ -57,6 +57,15 @@
|
|||
|
||||
#include <juce_core/juce_core.h>
|
||||
|
||||
//==============================================================================
|
||||
/** Config: JUCE_EXECUTE_APP_SUSPEND_ON_IOS_BACKGROUND_TASK
|
||||
Will execute your application's suspend method on an iOS background task, giving
|
||||
you extra time to save your applications state.
|
||||
*/
|
||||
#ifndef JUCE_EXECUTE_APP_SUSPEND_ON_BACKGROUND_TASK
|
||||
#define JUCE_EXECUTE_APP_SUSPEND_ON_BACKGROUND_TASK 0
|
||||
#endif
|
||||
|
||||
#if JUCE_EVENTS_INCLUDE_WINRT_WRAPPER && JUCE_WINDOWS
|
||||
#include <hstring.h>
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -37,9 +37,11 @@ Array<AppInactivityCallback*> appBecomingInactiveCallbacks;
|
|||
|
||||
@interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
|
||||
{
|
||||
UIBackgroundTaskIdentifier appSuspendTask;
|
||||
}
|
||||
|
||||
@property (strong, nonatomic) UIWindow *window;
|
||||
- (id)init;
|
||||
- (void) applicationDidFinishLaunching: (UIApplication*) application;
|
||||
- (void) applicationWillTerminate: (UIApplication*) application;
|
||||
- (void) applicationDidEnterBackground: (UIApplication*) application;
|
||||
|
|
@ -52,6 +54,14 @@ Array<AppInactivityCallback*> appBecomingInactiveCallbacks;
|
|||
|
||||
@implementation JuceAppStartupDelegate
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
appSuspendTask = UIBackgroundTaskInvalid;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) applicationDidFinishLaunching: (UIApplication*) application
|
||||
{
|
||||
ignoreUnused (application);
|
||||
|
|
@ -76,10 +86,31 @@ Array<AppInactivityCallback*> appBecomingInactiveCallbacks;
|
|||
|
||||
- (void) applicationDidEnterBackground: (UIApplication*) application
|
||||
{
|
||||
ignoreUnused (application);
|
||||
|
||||
if (JUCEApplicationBase* const app = JUCEApplicationBase::getInstance())
|
||||
{
|
||||
#if JUCE_EXECUTE_APP_SUSPEND_ON_BACKGROUND_TASK
|
||||
appSuspendTask = [application beginBackgroundTaskWithName:@"JUCE Suspend Task" expirationHandler:^{
|
||||
if (appSuspendTask != UIBackgroundTaskInvalid)
|
||||
{
|
||||
[application endBackgroundTask:appSuspendTask];
|
||||
appSuspendTask = UIBackgroundTaskInvalid;
|
||||
}
|
||||
}];
|
||||
|
||||
MessageManager::callAsync ([self,application,app] ()
|
||||
{
|
||||
app->suspended();
|
||||
if (appSuspendTask != UIBackgroundTaskInvalid)
|
||||
{
|
||||
[application endBackgroundTask:appSuspendTask];
|
||||
appSuspendTask = UIBackgroundTaskInvalid;
|
||||
}
|
||||
});
|
||||
#else
|
||||
ignoreUnused (application);
|
||||
app->suspended();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
- (void) applicationWillEnterForeground: (UIApplication*) application
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue