简体   繁体   中英

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

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. 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.

  1. Once per notification, but only if the app is running . If the app is open (ie 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).

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