ios - 应用程序在前台时的推送通知样式

标签 ios push-notification uialertview

当我测试我的 iOS 应用程序时,我将通知样式首选项设置为横幅样式。当我的应用程序不在前台(在后台或关闭时)时,此方法有效。但是,当应用程序处于前台时,通知显示为 UIAlertView

这是 Apple 设计的吗?或者我可能缺少一些我可以应用的设置?

最佳答案

您可以在 AppDelegate.m 中使用 application:didReceiveRemoteNotification:fetchCompletionHandler:。这样你就可以按照你想要的方式处理通知。有时不需要在 UIAlertView 中显示任何内容,但您想更新特定的 UILabels 或任何其他内容。您还会获得一个 userInfo,您可以在其中获取有关您的 Push 的更多具体信息。您还可以确定您目前处于哪种模式:

if ( application.applicationState == UIApplicationStateInactive 
     || application.applicationState == UIApplicationStateBackground  ) {

} else {

}

The Documentation says:

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/

相关文章:

push-notification - react native : Call a function from tapping a Push Notification?

ios - 如何使用分发配置文件/证书测试 ios 应用程序的推送通知?

带有 Firebase 数据字符串的 Swift Firebase UIAlertView

ios - UIAlertView 用于在搜索中找不到匹配项

ios - 同时录制和播放音频的问题

ios - 如何在 swift 4 的 UILabel 中找到子字符串的框架?

android - 推送通知需要很长时间才能到达

ios - 在 MonoTouch 中为 ToolbarItems.UIBarButtonItem 设置 BadgeValue

ios - 如何将 base 64 图像数据字符串提供给 UIWebView?

IOS 8 无法从 UITextField 中关闭键盘