简体   繁体   English

如何在iOS应用程序的前台同时出现多个推送通知时进行处理

[英]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. 我已经在应用程序的委托方法中向服务器发送了请求:(UIApplication *)application didReceiveRemoteNotification:但是当多个推送通知同时出现时,应用程序由于没有而崩溃。 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.......... // getEventFromServer:用于发送请求和获取响应的方法。

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? 发送http请求和获取响应之间需要多少时间(最长时间)?
  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. 对于到达您设备的每个推送通知,它将被调用一次,但是如果您一次将太多通知发送到同一设备,则APNS服务器可能只会将其中一些通知发送到设备。

  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 . 如果在通知到达时应用程序处于打开状态(即用户正在使用该应用程序),则iOS不会显示通知消息,您需要使用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. 同步HTTP往返时间可能花费太多时间。 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). 看看如何通过移动后端平台 (如Parse.com或InnoQuant MOCA)解决此问题(我在InnoQuant工作)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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