iOS应用程序前台同时出现多个推送通知时如何处理 [英] how to handle while multiple push notification comes at same time in foreground of app in iOS

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

问题描述

我已经在 application:(UIApplication *)application didReceiveRemoteNotification: 的委托方法中向服务器发送请求,但是当多个推送通知同时出现时,应用程序因为没有而崩溃.请求到达服务器.

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:发送请求和获取响应的方法.........

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

请建议我如何处理.

  1. 当多个推送通知到来时,委托方法调用了多少次?
  2. 发送 http 请求和获得响应之间需要多长时间(最长时间)?

推荐答案

  1. 每个通知一次,但仅限应用正在运行时.如果应用程序打开(即用户正在使用应用程序)而通知到达时,iOS 不会显示通知消息,您需要使用 application:(UIApplication *)application didReceiveRemoteNotification 处理它.否则(应用未运行),用户可以选择通过点击任何推送通知来启动应用.

  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.

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

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天全站免登陆