据我了解,当应用程序正在运行或在前台运行且收到推送通知时,该应用程序不应显示任何警报,但应用程序委托将调用didReceiveRemoteNotification
委托方法,我应在该回调中处理推送通知。
推送通知应仅在应用程序处于后台时显示警报/横幅。
但是,我们的应用有时会(并非始终)在运行或在前台运行时通过OK按钮获得推送通知警报。我想知道这是否是iOS 7中的新功能(我从未听说过),或者是因为我正在使用UrbanAirship
来为使用用户alias
的iOS应用程序进行推送通知。该应用程序将在运行时显示推送警报,并在didReceiveRemoteNotification
中运行回调。
为此抓挠头。有人知道为什么吗?
[当应用程序处于前台状态时,它不应显示任何内容。
如果看到alertView,则表示您已为其提供代码。
遵循以下内容:
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {
//app is in foreground
//the push is in your control
} else {
//app is in background:
//iOS is responsible for displaying push alerts, banner etc..
}
}
如果已实现pushNotificationDelegate
[UAPush shared].pushNotificationDelegate = self;
然后覆盖,并将其留空
- (void)displayNotificationAlert:(NSString *)alertMessage
{
//do nothing
}
由于您的代码中配置Urban Airship的方式,您很可能会看到其他推送通知。从Urban Airship's docs:
The sample UI includes an implementation of UAPushNotificationDelegate that handles alerts, sounds, and badges. However, if you wish to customize this behavior, you can provide your own implementation:
[UAPush shared].pushNotificationDelegate = customPushDelegate;
[有关使用Urban Airship in their support articles处理推送通知的正确方法的更多信息。由于您使用的是UA,因此建议您在前台使用它们的委托等来处理传入的推送通知,而不要在didReceiveRemoteNotification
应用程序委托方法中实现自己的代码。
希望这对您有帮助...否则,请发布您的代码,以便我们可以解密正在发生的情况。这确实是非常奇怪的行为!
此答案适用于寻找相同内容的迅速用户
let state = application.applicationState
if (state == .active) {
//app is in foreground
//the push is in your control
} else {
//app is in background:
//iOS is responsible for displaying push alerts, banner etc..
}
[如果您还有其他疑问,请参阅检查的答案。Apple Documentation on handling Notifications