how to handle while multiple push notification comes at same time in foreground of app in iOS

情到浓时终转凉″ 提交于 2019-12-24 16:42:13

问题


I have send request to server in delegate method of application:(UIApplication *)application didReceiveRemoteNotification: but when multiple push notification comes at same time app get crash because of no. of request goes to server.

In delegate method I write below code:

 if (!downloadInboxQueue) {
                    downloadInboxQueue = [[NSOperationQueue alloc] init];
                    downloadInboxQueue.maxConcurrentOperationCount=1;
                }

            NSNumber *ischatnumber=[[NSNumber alloc] initWithInt:0]; 
                operationObject=[[Operation_Inbox alloc] init];   

                NSInvocationOperation *operation22= [[NSInvocationOperation alloc] initWithTarget:operationObject selector:@selector(getEventFromServer:) object:ischatnumber];
                [downloadInboxQueue addOperation:operation22]; 
                operation22=nil;
                NSInvocationOperation *operation2= [[NSInvocationOperation alloc] initWithTarget:operationObject selector:@selector(getEventFromServer:) object:ischatnumber];
                [downloadInboxQueue addOperation:operation2];   
                operation2=nil;

//getEventFromServer: method for sending request and get response..........

please suggest me how to handle that .

  1. how many times delegate method called when multiple push notification comes ?
  2. how much time required (max. time)between send http request and get response?

回答1:


  1. It would be called once for each push notification that arrives to your device, but if you send too many notifications to the same device at once, it's possible that the APNS server will send only some of them to the device.

  2. That's not something you should rely on. You should make an async call to your server, in order not to hang/crash your app.




回答2:


  1. Once per notification, but only if the app is running. If the app is open (i.e. the user is using the app) while the notification arrives, iOS doesnt show a notification message, you need to handle it using application:(UIApplication *)application didReceiveRemoteNotification. Otherwise (the app is not running), the user may choose to start the app by clicking on any push notification.

  2. The synchronous HTTP roundtrip time could take too much time. Avoid synchronous calls in delegate methods. You could enqueue requests to the server in a persistent local storage and eventually send them asynchronously to the server when network connection is available. Have a look at how this is solved by Mobile Backend Platforms such as Parse.com or InnoQuant MOCA (I work at InnoQuant).



来源:https://stackoverflow.com/questions/16716455/how-to-handle-while-multiple-push-notification-comes-at-same-time-in-foreground

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!