关于ios网络杂记

来源:互联网 发布:js 左右滑动切换特效 编辑:程序博客网 时间:2024/04/29 05:58

网络程序的问题:

1. 随机断网

2.断点继续

3.网络不存在,如何处理中断,尤其是某个应用在有网络和无网络情况下多能够使用,请问该如何处理?

4.应该不存在最后确认的问题。



At WWDC2010, for network programming, Apple recommends to use asynchronous programming with RunLoop.

  • WWDC 2010 Session 207 - Network Apps for iPhone OS, Part 1
  • WWDC 2010 Session 208 - Network Apps for iPhone OS, Part 2

NSURLConnection asynchronous request is one of the most efficient way. But if you want to use ASIHTTPRequest, how about it? (ASIHTTPRequest asynchronous request is implemented using NSOperationQueue, it is not same as NSURLConnection asynchronous.)

ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];[request setCompletionBlock:^{    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{        NSData *responseData = [request responseData];        /* Parse JSON, ... */        dispatch_async(dispatch_get_main_queue(), ^{            callbackBlock(array);        });    });}];[request setFailedBlock:^{    NSError *error = [request error];    /* error handling */}];[request startAsynchronous];
通过notification来做,那请问如何保证,在你ready的时候,原来的picker view还在呢?也许被遮盖了,也许消失了。 how to balance these?

You can use NSNotificationCenter to post a notification to update the picker when the data has finished loading

Create the notification

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshPicker) name: @"WEBSERVICE_UPDATED" object:nil];

Post the notification

[[NSNotificationCenter defaultCenter] postNotificationName:@"WEBSERVICE_UPDATED" object:lesson];-(void)refreshPicker {     // Handle refresh here     [pickerViewController reloadAllComponents];}

原创粉丝点击