application: didReceiveRemoteNotification: fetchCompletionHandler: called more than once.How to avoid?

Viewed 797

I have an application, that uses Remote/Push notifications.

Background mode for remote notification is used, and everything works as expected.Application wakes up and takes all needed data from server.

But if Push notification alert is not cleared from Notification Center, and user click it application: didReceiveRemoteNotification: fetchCompletionHandler: method will be called again, and that means it will send new request to server, and that is undesirable behaviour.

First option is to check application state, but that causing me a problems, when application is in suspended.I have to do something like code below, but this doesn't work for me:

    if([UIApplication sharedApplication].applicationState == UIApplicationStateActive || [UIApplication sharedApplication].applicationState == UIApplicationStateBackground){

    }
    if([UIApplication sharedApplication].applicationState  == UIApplicationStateInactive){

    }

Second option is, whether there is a way to clear alerts from Notification Center when user opens application, but I cannot find way to do it.

So is there a way to avoid second call of application:didReceiveRemoteNotification: fetchCompletionHandler: method?

1 Answers
Related