iOS 应用关闭时通知块
iOS notification block if app closed
我已经设置了通知,一切正常。但是,即使应用程序关闭,通知仍会显示。我只希望用户在应用程序处于后台时收到通知。
UIApplicationState 似乎只处理 Active、Inactive 和 Background,Inactive 似乎适用于 运行 应用程序的中断。
如果应用程序关闭,阻止通知的程序是什么?
谢谢。
编辑:正如 shallowThought 指出的,我在这里指的是推送通知,但没有考虑与本地通知的混淆
对于本地通知:
你不能保证这一点。您可以删除 applicationWillTerminate
中的所有 NSNotifications
。它不会在 suspended
状态下工作。
If your app is running (either in the foreground or background) at termination time, the system calls your app delegate’s applicationWillTerminate: method so that you can perform any required cleanup. You can use this method to save user data or app state information that you would use to restore your app to its current state on a subsequent launch. Your method has approximately 5 seconds to perform any tasks and return. If it does not return in time, the app is killed and removed from memory.
Important: The applicationWillTerminate: method is not called if your app is currently suspended.
对于推送通知:
您可以发送(推送)静默通知。这会唤醒您的应用程序。假设您跟踪应用程序的生命周期状态,您可以安排本地通知以备不时之需通知用户。
我已经设置了通知,一切正常。但是,即使应用程序关闭,通知仍会显示。我只希望用户在应用程序处于后台时收到通知。
UIApplicationState 似乎只处理 Active、Inactive 和 Background,Inactive 似乎适用于 运行 应用程序的中断。
如果应用程序关闭,阻止通知的程序是什么?
谢谢。
编辑:正如 shallowThought 指出的,我在这里指的是推送通知,但没有考虑与本地通知的混淆
对于本地通知:
你不能保证这一点。您可以删除 applicationWillTerminate
中的所有 NSNotifications
。它不会在 suspended
状态下工作。
If your app is running (either in the foreground or background) at termination time, the system calls your app delegate’s applicationWillTerminate: method so that you can perform any required cleanup. You can use this method to save user data or app state information that you would use to restore your app to its current state on a subsequent launch. Your method has approximately 5 seconds to perform any tasks and return. If it does not return in time, the app is killed and removed from memory.
Important: The applicationWillTerminate: method is not called if your app is currently suspended.
对于推送通知:
您可以发送(推送)静默通知。这会唤醒您的应用程序。假设您跟踪应用程序的生命周期状态,您可以安排本地通知以备不时之需通知用户。