diff --git a/doc/classes/MainLoop.xml b/doc/classes/MainLoop.xml
index 3092c822019..daeb1793f7e 100644
--- a/doc/classes/MainLoop.xml
+++ b/doc/classes/MainLoop.xml
@@ -201,11 +201,12 @@
Notification received from the OS when the app is resumed.
- Specific to the Android platform.
+ Specific to mobile platforms.
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.
diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml
index 827accb47a6..ad3f7e2aa59 100644
--- a/doc/classes/Node.xml
+++ b/doc/classes/Node.xml
@@ -928,11 +928,12 @@
Notification received from the OS when the app is resumed.
- Specific to the Android platform.
+ Specific to mobile platforms.
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.
Inherits pause mode from the node's parent. For the root node, it is equivalent to [constant PAUSE_MODE_STOP]. Default.
diff --git a/platform/iphone/app_delegate.mm b/platform/iphone/app_delegate.mm
index beed54dd5fe..714846191d5 100644
--- a/platform/iphone/app_delegate.mm
+++ b/platform/iphone/app_delegate.mm
@@ -174,6 +174,14 @@ static ViewController *mainViewController = nil;
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 {
self.window = nil;
}
diff --git a/platform/iphone/os_iphone.h b/platform/iphone/os_iphone.h
index 013c3411e5f..3c18578b0a2 100644
--- a/platform/iphone/os_iphone.h
+++ b/platform/iphone/os_iphone.h
@@ -204,6 +204,9 @@ public:
void on_focus_out();
void on_focus_in();
+
+ void on_enter_background();
+ void on_exit_background();
};
#endif // IPHONE_ENABLED
diff --git a/platform/iphone/os_iphone.mm b/platform/iphone/os_iphone.mm
index 516b8ae0c9b..85c246618de 100644
--- a/platform/iphone/os_iphone.mm
+++ b/platform/iphone/os_iphone.mm
@@ -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