如何处理在多个推送通知在iOS应用中的前景正值同时 [英] how to handle while multiple push notification comes at same time in foreground of app in iOS

查看:301
本文介绍了如何处理在多个推送通知在iOS应用中的前景正值同时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序的委托方法发送请求给服务器:(UIApplication的*)应用didReceiveRemoteNotification:但是当多个推送通知正值同时应用得到,因为没有崩溃。的请求转到服务器。

在委托方法我下面写code:

 如果(!downloadInboxQueue){
                    downloadInboxQueue = [[NSOperationQueue的alloc]初始化];
                    downloadInboxQueue.maxConcurrentOperationCount = 1;
                }            *的NSNumber = ischatnumber [[NSNumber的页头] initWithInt:0];
                operationObject = [[Operation_Inbox的alloc]初始化];                NSInvocationOperation * operation22 = [[NSInvocationOperation页头] initWithTarget:operationObject选择:@选择(getEventFromServer :)对象:ischatnumber];
                [downloadInboxQueue addOperation:operation22];
                operation22 =零;
                NSInvocationOperation *操作2 = [[NSInvocationOperation页头] initWithTarget:operationObject选择:@选择(getEventFromServer :)对象:ischatnumber];
                [downloadInboxQueue addOperation:操作2];
                操作2 =零;

// getEventFromServer:发送请求和响应获取方法..........

请建议我如何处理。


  1. 当多个推送通知来调用多少次委托方法?

  2. 发送HTTP请求和响应获得的
  3. 需要多少时间(最大时间)?


解决方案

  1. 每一次通知,但只有当应用程序正在运行即可。如果应用程序是开放的(即用户正在使用的应用程序),而通知到达,iOS的犯规显示通知消息,您需要使用处理它应用程序:(的UIApplication *)应用didReceiveRemoteNotification 。否则(应用程序没有运行),用户可以通过单击任何推送通知,启动应用程序。


  2. 同步HTTP往返时间可能需要太多的时间。避免在委托方法同步调用。你可以排队请求到服务器在持久本地存储和最终异步发送他们到服务器时,网络连接可用。看看这是如何移动后端平台如Parse.com或InnoQuant MOCA(我在InnoQuant工作)来解决。


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

这篇关于如何处理在多个推送通知在iOS应用中的前景正值同时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆