简体   繁体   中英

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

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?

您可以在APNS消息中发送唯一ID,然后通过记住该ID来过滤第二个呼叫 - 在您的应用程序的临时集合中(如果您在收到并点击APNS消息之间杀死应用程序,则会第二次调用)或持久存储(到在任何情况下都避免二次通话)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM