当我测试我的 iOS 应用程序时,我将通知样式首选项设置为横幅样式。当我的应用程序不在前台(在后台或关闭时)时,此方法有效。但是,当应用程序处于前台时,通知显示为 UIAlertView
。
这是 Apple 设计的吗?或者我可能缺少一些我可以应用的设置?
最佳答案
您可以在 AppDelegate.m
中使用 application:didReceiveRemoteNotification:fetchCompletionHandler:
。这样你就可以按照你想要的方式处理通知。有时不需要在 UIAlertView
中显示任何内容,但您想更新特定的 UILabels
或任何其他内容。您还会获得一个 userInfo
,您可以在其中获取有关您的 Push
的更多具体信息。您还可以确定您目前处于哪种模式:
if ( application.applicationState == UIApplicationStateInactive
|| application.applicationState == UIApplicationStateBackground ) {
} else {
}
Use this method to process incoming remote notifications for your app. Unlike the application:didReceiveRemoteNotification: method, which is called only when your app is running in the foreground, the system calls this method when your app is running in the foreground or background. In addition, if you enabled the remote notifications background mode, the system launches your app (or wakes it from the suspended state) and puts it in the background state when a push notification arrives. However, the system does not automatically launch your app if the user has force-quit it. In that situation, the user must relaunch your app or restart the device before the system attempts to launch your app automatically again.
关于ios - 应用程序在前台时的推送通知样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28326703/