diff --git a/core/pen/include/os.h b/core/pen/include/os.h index 1d22e787..c5d45213 100644 --- a/core/pen/include/os.h +++ b/core/pen/include/os.h @@ -55,6 +55,7 @@ namespace pen bool os_set_keychain_item(const Str& identifier, const Str& key, const Str& value); Str os_get_keychain_item(const Str& identifier, const Str& key); bool os_is_backgrounded(); + void os_register_background_callback(void (*callback)(bool)); // music struct music_item diff --git a/core/pen/source/ios/os.mm b/core/pen/source/ios/os.mm index 72372cee..36098c57 100644 --- a/core/pen/source/ios/os.mm +++ b/core/pen/source/ios/os.mm @@ -83,6 +83,7 @@ -(MPRemoteCommandHandlerStatus)like; pen_text_field* text_field = nullptr; bool show_on_screen_keyboard = false; pen::music_player_remote music_remote; + void (*background_callback)(bool) = nullptr; }; os_context s_context; @@ -172,6 +173,24 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N } } +- (void)applicationWillResignActive:(UIApplication *)app +{ + // pairs with applicationDidBecomeActive + if(s_context.background_callback) + { + s_context.background_callback(true); + } +} + +- (void)applicationDidBecomeActive:(UIApplication *)app +{ + // pairs with applicationWillResignActive + if(s_context.background_callback) + { + s_context.background_callback(true); + } +} + -(MPRemoteCommandHandlerStatus)play { if(s_context.music_remote.pause) { @@ -799,4 +818,9 @@ void music_set_now_playing_time_info(u32 position_ms, u32 duration_ms) bool os_is_backgrounded() { return [[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground; } + + void os_register_background_callback(void (*callback)(bool)) + { + s_context.background_callback = callback; + } }