mirror of
https://github.com/encounter/SDL.git
synced 2025-05-29 02:31:27 +00:00
[UIKit] handle app lifecycle events in a custom object instead of AppDelegate
removes the need to call SDL counterparts manually when custom AppDelegate is used
This commit is contained in:
parent
c9f60cce40
commit
5b13136471
@ -434,43 +434,6 @@ SDL_LoadLaunchImageNamed(NSString *name, int screenh)
|
|||||||
/* Do nothing. */
|
/* Do nothing. */
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !TARGET_OS_TV
|
|
||||||
- (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation
|
|
||||||
{
|
|
||||||
SDL_OnApplicationDidChangeStatusBarOrientation();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
- (void)applicationWillTerminate:(UIApplication *)application
|
|
||||||
{
|
|
||||||
SDL_OnApplicationWillTerminate();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
|
|
||||||
{
|
|
||||||
SDL_OnApplicationDidReceiveMemoryWarning();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)applicationWillResignActive:(UIApplication*)application
|
|
||||||
{
|
|
||||||
SDL_OnApplicationWillResignActive();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)applicationDidEnterBackground:(UIApplication*)application
|
|
||||||
{
|
|
||||||
SDL_OnApplicationDidEnterBackground();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)applicationWillEnterForeground:(UIApplication*)application
|
|
||||||
{
|
|
||||||
SDL_OnApplicationWillEnterForeground();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)applicationDidBecomeActive:(UIApplication*)application
|
|
||||||
{
|
|
||||||
SDL_OnApplicationDidBecomeActive();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)sendDropFileForURL:(NSURL *)url
|
- (void)sendDropFileForURL:(NSURL *)url
|
||||||
{
|
{
|
||||||
NSURL *fileURL = url.filePathURL;
|
NSURL *fileURL = url.filePathURL;
|
||||||
|
@ -41,10 +41,84 @@
|
|||||||
|
|
||||||
static BOOL UIKit_EventPumpEnabled = YES;
|
static BOOL UIKit_EventPumpEnabled = YES;
|
||||||
|
|
||||||
|
|
||||||
|
@interface SDL_LifecycleObserver : NSObject
|
||||||
|
@property (nonatomic, assign) BOOL isObservingNotifications;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation SDL_LifecycleObserver
|
||||||
|
|
||||||
|
- (void)eventPumpChanged
|
||||||
|
{
|
||||||
|
NSNotificationCenter *notificationCenter = NSNotificationCenter.defaultCenter;
|
||||||
|
if (UIKit_EventPumpEnabled && !self.isObservingNotifications) {
|
||||||
|
self.isObservingNotifications = YES;
|
||||||
|
[notificationCenter addObserver:self selector:@selector(applicationDidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
|
||||||
|
[notificationCenter addObserver:self selector:@selector(applicationWillResignActive) name:UIApplicationWillResignActiveNotification object:nil];
|
||||||
|
[notificationCenter addObserver:self selector:@selector(applicationDidEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
|
||||||
|
[notificationCenter addObserver:self selector:@selector(applicationWillEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
|
||||||
|
[notificationCenter addObserver:self selector:@selector(applicationWillTerminate) name:UIApplicationWillTerminateNotification object:nil];
|
||||||
|
[notificationCenter addObserver:self selector:@selector(applicationDidReceiveMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
|
||||||
|
#if !TARGET_OS_TV
|
||||||
|
[notificationCenter addObserver:self selector:@selector(applicationDidChangeStatusBarOrientation) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
|
||||||
|
#endif
|
||||||
|
} else if (!UIKit_EventPumpEnabled && self.isObservingNotifications) {
|
||||||
|
self.isObservingNotifications = NO;
|
||||||
|
[notificationCenter removeObserver:self];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)applicationDidBecomeActive
|
||||||
|
{
|
||||||
|
SDL_OnApplicationDidBecomeActive();
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)applicationWillResignActive
|
||||||
|
{
|
||||||
|
SDL_OnApplicationWillResignActive();
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)applicationDidEnterBackground
|
||||||
|
{
|
||||||
|
SDL_OnApplicationDidEnterBackground();
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)applicationWillEnterForeground
|
||||||
|
{
|
||||||
|
SDL_OnApplicationWillEnterForeground();
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)applicationWillTerminate
|
||||||
|
{
|
||||||
|
SDL_OnApplicationWillTerminate();
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)applicationDidReceiveMemoryWarning
|
||||||
|
{
|
||||||
|
SDL_OnApplicationDidReceiveMemoryWarning();
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !TARGET_OS_TV
|
||||||
|
- (void)applicationDidChangeStatusBarOrientation
|
||||||
|
{
|
||||||
|
SDL_OnApplicationDidChangeStatusBarOrientation();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SDL_iPhoneSetEventPump(SDL_bool enabled)
|
SDL_iPhoneSetEventPump(SDL_bool enabled)
|
||||||
{
|
{
|
||||||
UIKit_EventPumpEnabled = enabled;
|
UIKit_EventPumpEnabled = enabled;
|
||||||
|
|
||||||
|
static SDL_LifecycleObserver *lifecycleObserver;
|
||||||
|
static dispatch_once_t onceToken;
|
||||||
|
dispatch_once(&onceToken, ^{
|
||||||
|
lifecycleObserver = [SDL_LifecycleObserver new];
|
||||||
|
});
|
||||||
|
[lifecycleObserver eventPumpChanged];
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user