4

I want to ignore push notifications when the app is active. I am handling notifications as follows:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{ 
    if (application.applicationState != UIApplicationStateActive)
    {
        [[PushHelper shared] processPush: userInfo];
    }
}

But when app is active and device receives push notification, the UIAlertView with notification message appears. How can I disable default handling from UA?

Marc Audet
  • 46,011
  • 11
  • 63
  • 83
scholl
  • 81
  • 1
  • 6

2 Answers2

6

I had the same problem and found solution. If define the delegate method displayNotificationAlert: of UAPushNotificationDelegate protocol with empty body, for example, then the automatic alerts will not be shown:

{   
   ...
   [[UAPush shared] registerForRemoteNotifications];
   [UAPush shared].pushNotificationDelegate = self;
   ...
}

- (void)displayNotificationAlert:(NSString *)alertMessage
{
}
SoVa_
  • 379
  • 4
  • 12
1

If you don't need to do anything with the push notification itself just remove the [[PushHelper shared] processPush: userInfo] from your code

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{ 
   //nothing to do here
}

The didReceiveRemoteNotification method is only called when the app is running.

Eric Genet
  • 1,260
  • 1
  • 9
  • 19
  • Awesome)) And how can I handle notification, when app returns from background after taping message from notification center? – scholl Aug 30 '13 at 14:35
  • you need to handle it in didFinishLaunchingWithOption method. The notification payload will be in the options dictionary – Eric Genet Aug 30 '13 at 14:38