2014-08-27 133 views
4

根据我的理解,当应用程序正在运行或处于前台并收到推送通知时,应用程序不应显示任何提醒,但应用程序代理将调用didReceiveRemoteNotification委托方法和我应该在回调中处理推送通知。当应用程序在前台运行时收到iOS推送通知

推送通知应该只在应用程序处于后台时显示警告/横幅。

但是,我们的应用程序在应用程序正在运行时或在前台有时(而不是全部时间)都会通过“确定”按钮获取推送通知警报。我想知道这是iOS 7中的新东西(我从来没有听说过这个),还是因为我使用UrbanAirship来为我们的iOS应用使用alias的推送通知。该应用程序将在运行时显示推送警报,并在didReceiveRemoteNotification中运行回调。

挠挠我的头。有谁知道为什么?

+0

如果您在收到推送通知时没有显示UIAlertView的代码,听起来好像是Urban Airship这样做。 – Mike 2014-08-27 16:16:14

回答

7

当应用程序在前台时,它不应该显示任何内容。

如果您看到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 
} 
+0

这就是我的问题。我收到2个警报视图。一个来自我的代码(与你的代码相同),另一个来自无处。我想如果城市飞艇负责第二次警报 – imObjCSwifting 2014-08-27 16:24:50

+1

请分享您的代码 – meda 2014-08-27 16:25:27

+0

是的UA是罪魁祸首。重写UA处理推送通知的工作。谢谢 – imObjCSwifting 2014-08-27 16:57:49

2

您AR e由于您的代码中配置了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;

有在处理与城市飞艇in their support articles推送通知的正确方法的更多信息。由于您使用的是UA,因此我建议您在前台使用其代表等来处理传入的推送通知,而不是在didReceiveRemoteNotification应用程序委托方法中实现自己的代码。

希望这有助于...如果没有,请发布您的代码,以便我们可以解密发生了什么。这确实是非常奇怪的行为!

+0

这一个应该是正确的。你也可以删除UI代码,或者在这里注释掉UIAlertView:https://github.com/urbanairship/ios-library/blob/master/Airship/UI/Default/Push/Classes/Shared/UAPushNotificationHandler.m #L33 – dperconti 2014-08-28 17:41:11

相关问题