ui2_ Sync Download

Source: Internet
Author: User

viewcontroller.m//ui2_ sync Download////Created by zhangxueming on 15/7/17.//Copyright (c) 2015 zhangxueming. All rights reserved.//#import "ViewController.h"//http://iappfree.candou.com:8080/free/applications/limited? currency=rmb&page= pages @interface Viewcontroller () {nsurlconnection *_urlconnection;//provided by Apple, to the client and the server to establish a connection NSMuta    Blearray *_dataarray; Provide data} @end//Synchronous Download: When sending a network request to the server, the UI cannot interact during the request data, only after the server has returned the data to perform subsequent operations//requests for a smaller amount of data, special requirements @implementation    viewcontroller-(void) viewdidload {[Super viewdidload];    Additional setup after loading the view, typically from a nib. [Self loaddatawithpage:4];} -(void) Loaddatawithpage: (Nsinteger) page{//Create URL object nsstring *urlstring = [NSString stringwithformat:@] Http://iappfr    Ee.candou.com:8080/free/applications/limited?currency=rmb&page=%ld ", page];    Nsurl *url = [Nsurl urlwithstring:urlstring]; Create data Request object//cachepolicy Cache protocol is an enumeration type://nsurlrequestuseprotocolcachepolicy basic policy//nsurlrequestreloadignOringlocalcachedata Ignore local cache//nsurlrequestreturncachedataelseload First use cache, if there is no local cache, download from the original address// Nsurlrequestreturncachedatadontload uses the local cache, never downloads, and if there is no cache locally, the request fails. This policy is mostly used for offline operations//nsurlrequestreloadignoringlocalandremotecachedata ignoring any cache policy, whether local or remote, always re-downloaded from the original address// Nsurlrequestreloadrevalidatingcachedata If the local cache is valid, it is not downloaded. Any other cases are re-downloaded from the original address nsurlrequest *request = [Nsurlrequest requestwithurl:url cachepolicy:    Nsurlrequestuseprotocolcachepolicy Timeoutinterval:10];    Status Response//404 (request failed) 200 (request succeeded) 400 (client syntax error) 500 (service-side error) Nshttpurlresponse *response= Nil;    Nserror *error = nil;        NSData *data = [nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&error];    Print Status Code NSLog (@ "%@", response);    NSLog (@ "code =%li", response.statuscode);        NSLog (@ "header =%@", response.allheaderfields);        ID result = [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutablecontainers Error:nil]; NSLog (@ "result=%@", result);} -(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end

ui2_ Sync Download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.