Merge pull request #85229 from ztc0611/3.x-ios-add-pause-resume-notifs
[3.x] Enhance mobile suspend MainLoop notifications
This commit is contained in:
commit
273d5897a0
5 changed files with 37 additions and 4 deletions
|
@ -201,11 +201,12 @@
|
||||||
</constant>
|
</constant>
|
||||||
<constant name="NOTIFICATION_APP_RESUMED" value="1014">
|
<constant name="NOTIFICATION_APP_RESUMED" value="1014">
|
||||||
Notification received from the OS when the app is resumed.
|
Notification received from the OS when the app is resumed.
|
||||||
Specific to the Android platform.
|
Specific to mobile platforms.
|
||||||
</constant>
|
</constant>
|
||||||
<constant name="NOTIFICATION_APP_PAUSED" value="1015">
|
<constant name="NOTIFICATION_APP_PAUSED" value="1015">
|
||||||
Notification received from the OS when the app is paused.
|
Notification received from the OS when the app is paused.
|
||||||
Specific to the Android platform.
|
Specific to mobile platforms.
|
||||||
|
[b]Note:[/b] On iOS, you only have approximately 5 seconds to finish a task started by this signal. If you go over this allotment, iOS will kill the app instead of pausing it.
|
||||||
</constant>
|
</constant>
|
||||||
</constants>
|
</constants>
|
||||||
</class>
|
</class>
|
||||||
|
|
|
@ -928,11 +928,12 @@
|
||||||
</constant>
|
</constant>
|
||||||
<constant name="NOTIFICATION_APP_RESUMED" value="1014">
|
<constant name="NOTIFICATION_APP_RESUMED" value="1014">
|
||||||
Notification received from the OS when the app is resumed.
|
Notification received from the OS when the app is resumed.
|
||||||
Specific to the Android platform.
|
Specific to mobile platforms.
|
||||||
</constant>
|
</constant>
|
||||||
<constant name="NOTIFICATION_APP_PAUSED" value="1015">
|
<constant name="NOTIFICATION_APP_PAUSED" value="1015">
|
||||||
Notification received from the OS when the app is paused.
|
Notification received from the OS when the app is paused.
|
||||||
Specific to the Android platform.
|
Specific to mobile platforms.
|
||||||
|
[b]Note:[/b] On iOS, you only have approximately 5 seconds to finish a task started by this signal. If you go over this allotment, iOS will kill the app instead of pausing it.
|
||||||
</constant>
|
</constant>
|
||||||
<constant name="PAUSE_MODE_INHERIT" value="0" enum="PauseMode">
|
<constant name="PAUSE_MODE_INHERIT" value="0" enum="PauseMode">
|
||||||
Inherits pause mode from the node's parent. For the root node, it is equivalent to [constant PAUSE_MODE_STOP]. Default.
|
Inherits pause mode from the node's parent. For the root node, it is equivalent to [constant PAUSE_MODE_STOP]. Default.
|
||||||
|
|
|
@ -174,6 +174,14 @@ static ViewController *mainViewController = nil;
|
||||||
OSIPhone::get_singleton()->on_focus_in();
|
OSIPhone::get_singleton()->on_focus_in();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||||
|
OSIPhone::get_singleton()->on_enter_background();
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||||
|
OSIPhone::get_singleton()->on_exit_background();
|
||||||
|
}
|
||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
self.window = nil;
|
self.window = nil;
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,6 +204,9 @@ public:
|
||||||
|
|
||||||
void on_focus_out();
|
void on_focus_out();
|
||||||
void on_focus_in();
|
void on_focus_in();
|
||||||
|
|
||||||
|
void on_enter_background();
|
||||||
|
void on_exit_background();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // IPHONE_ENABLED
|
#endif // IPHONE_ENABLED
|
||||||
|
|
|
@ -865,4 +865,24 @@ void OSIPhone::on_focus_in() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OSIPhone::on_enter_background() {
|
||||||
|
// Do not check for is_focused, because on_focus_out will always be fired first by applicationWillResignActive.
|
||||||
|
|
||||||
|
if (get_main_loop()) {
|
||||||
|
get_main_loop()->notification(MainLoop::NOTIFICATION_APP_PAUSED);
|
||||||
|
}
|
||||||
|
|
||||||
|
on_focus_out();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OSIPhone::on_exit_background() {
|
||||||
|
if (!is_focused) {
|
||||||
|
on_focus_in();
|
||||||
|
|
||||||
|
if (get_main_loop()) {
|
||||||
|
get_main_loop()->notification(MainLoop::NOTIFICATION_APP_RESUMED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue