APNS推送消息到达后的处理流程

 APN push的消息到达后,UIApplicationDelegate有两个方法和处理消息有关:

  1. application:didReceiveRemoteNotification:
  2. application:didFinishLaunchingWithOptions:

下面的流程图显示了app在处理推送消息的一个流程。

 

测试推送的流程时,有两个难题:

  1. 推送需要服务端配合,搭建整个远程推送的环境很困难。
  2. 在测试程序没有运行时,没有有效的办法检测程序的处理流程。

针对上面的问题,在测试过程中分别找到了对应的处理方式。

第一个问题的解决办法是用本地推送来代替远程推送。经查阅apple的官方文档:
http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/WhatAreRemoteNotif.html#//apple_ref/doc/uid/TP40008194-CH102-SW1

远程推送和本地推送在处理流程上是一致的,不同的地方是delegate的方法和参数不同。所以只是测试推送在应用端的处理流程的话,是可以用本地推送模拟远程推送的。

 

第二个问题的解决方案是输出的重定向:参靠下面的网址:

http://stackoverflow.com/questions/2103141/iphone-once-i-have-redirected-nslog-to-a-file-how-do-i-revert-it-to-the-consol

具体代码如下:

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString *logPath = [documentsDirectory stringByAppendingPathComponent:@"console.log"];

    freopen([logPath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);

    

    NSLog(@"application didFinishLaunchingWithOptions");

 

将stderr重定向到一个文件后,所有NSLog的输出就由console转到了指定的文件。

 

 



 

 

 

猜你喜欢

转载自gypgyp.iteye.com/blog/1871006
今日推荐