applicationDidEnterBackground 和 applicationWillTerminate 都在用户向上滑动退出应用程序时调用
applicationDidEnterBackground and applicationWillTerminate both called when user swipes up to quit app
我正在为用户将应用程序发送到后台或完全退出应用程序时添加一些通知。然而,当他们退出应用程序时,applicationDidEnterBackground
和 applicationWillTerminate
方法都会被调用。为什么会这样,当用户退出应用程序时,我怎样才能让 applicationWillTerminate
被调用?
这是objective-c,如果有人想知道的话。
applicationWillTerminate
方法只有在应用程序终止时不处于挂起状态时才会被调用。
以下链接可能对您有所帮助 -
Which function is called when iPhone app is terminated?
applicationWillTerminate when is it called and when not
看到 applicationWillTerminate
在 applicationDidEnterBackground
之后调用,我决定将 notification.fireDate
从调用 applicationDidEnterBackground
的点开始设置为 1 秒。当调用 applicationWillTerminate
时,它首先取消在 applicationDidEnterBackground
.
内安排的通知
伪代码:
-applicationDidEnterBackground()
{
[self scheduleLocalNotificationAtTimeIntervalFromNow:1.0f identifier: @"someIdentifier"];
}
-applicationWillTerminate
{
[self cancelLocalNotificationWithIdentifier: @"someIdentifier"];
[self scheduleLocalNotificationAtTimeIntervalFromNow:0.0f identifier: @"irrelevantIdentifier"];
}
我正在为用户将应用程序发送到后台或完全退出应用程序时添加一些通知。然而,当他们退出应用程序时,applicationDidEnterBackground
和 applicationWillTerminate
方法都会被调用。为什么会这样,当用户退出应用程序时,我怎样才能让 applicationWillTerminate
被调用?
这是objective-c,如果有人想知道的话。
applicationWillTerminate
方法只有在应用程序终止时不处于挂起状态时才会被调用。
以下链接可能对您有所帮助 -
Which function is called when iPhone app is terminated?
applicationWillTerminate when is it called and when not
看到 applicationWillTerminate
在 applicationDidEnterBackground
之后调用,我决定将 notification.fireDate
从调用 applicationDidEnterBackground
的点开始设置为 1 秒。当调用 applicationWillTerminate
时,它首先取消在 applicationDidEnterBackground
.
伪代码:
-applicationDidEnterBackground()
{
[self scheduleLocalNotificationAtTimeIntervalFromNow:1.0f identifier: @"someIdentifier"];
}
-applicationWillTerminate
{
[self cancelLocalNotificationWithIdentifier: @"someIdentifier"];
[self scheduleLocalNotificationAtTimeIntervalFromNow:0.0f identifier: @"irrelevantIdentifier"];
}