Skip to content

Commit 32e7029

Browse files
committed
- add background callback register function and hook into ios background notifcation functions
1 parent 9a9d1b1 commit 32e7029

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

core/pen/include/os.h

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ namespace pen
5555
bool os_set_keychain_item(const Str& identifier, const Str& key, const Str& value);
5656
Str os_get_keychain_item(const Str& identifier, const Str& key);
5757
bool os_is_backgrounded();
58+
void os_register_background_callback(void (*callback)(bool));
5859

5960
// music
6061
struct music_item

core/pen/source/ios/os.mm

+24
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ -(MPRemoteCommandHandlerStatus)like;
8383
pen_text_field* text_field = nullptr;
8484
bool show_on_screen_keyboard = false;
8585
pen::music_player_remote music_remote;
86+
void (*background_callback)(bool) = nullptr;
8687
};
8788
os_context s_context;
8889

@@ -172,6 +173,24 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N
172173
}
173174
}
174175

176+
- (void)applicationWillResignActive:(UIApplication *)app
177+
{
178+
// pairs with applicationDidBecomeActive
179+
if(s_context.background_callback)
180+
{
181+
s_context.background_callback(true);
182+
}
183+
}
184+
185+
- (void)applicationDidBecomeActive:(UIApplication *)app
186+
{
187+
// pairs with applicationWillResignActive
188+
if(s_context.background_callback)
189+
{
190+
s_context.background_callback(true);
191+
}
192+
}
193+
175194
-(MPRemoteCommandHandlerStatus)play {
176195
if(s_context.music_remote.pause)
177196
{
@@ -799,4 +818,9 @@ void music_set_now_playing_time_info(u32 position_ms, u32 duration_ms)
799818
bool os_is_backgrounded() {
800819
return [[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground;
801820
}
821+
822+
void os_register_background_callback(void (*callback)(bool))
823+
{
824+
s_context.background_callback = callback;
825+
}
802826
}

0 commit comments

Comments
 (0)