Network data synchronization Request loading

Source: Internet
Author: User

#import "ViewController.h"

@interface Viewcontroller ()

@property (nonatomic,weak) iboutlet UIButton *button;

@property (nonatomic,weak) iboutlet Uiimageview *imageview;


@end


@implementation Viewcontroller

-(Ibaction) Btnclick: (ID) sender
{
Give a URL string
NSString *str = @ "http://iappfree.candou.com:8080/free/applications/limited?currency=rmb&page=3";

NSString *str2 = @ "http://photo.candou.com/i/114/826ea823e8ffe792a6fda9e126f6c404";
Encapsulated as a usable URL type;
Nsurl *url = [Nsurl urlwithstring:str];
Nsurl *URL2 = [Nsurl urlwithstring:str2];

[Self syncdownloadwithstring:url];
[Self syncdownloadwithdata:url2];
}

#pragma synchronization request for the Mark-nsdate class method-

-(void) Syncdownloadwithdata: (Nsurl *) url{
Synchronous request method provided by binary data
NSData *data = [NSData Datawithcontentsofurl:url];

NSData-->uiimage
UIImage *image = [UIImage imagewithdata:data];

UIImage-->nsdata
NSData *dataimage = uiimagepngrepresentation (image);
NSData *dataimage2 = uiimagejpegrepresentation (image, 0.5);
UIImage *image3 = [UIImage imagewithcontentsoffile:@ ""];





Self.imageView.image = image;

NSLog (@ "Download complete");
}

#pragma synchronization request for the Mark-nsstring class method-
-(void) syncdownloadwithstring: (Nsurl *) url{

Methods for synchronizing requests provided by strings
Nserror *error;
NSString *str = [[NSString alloc]initwithcontentsofurl:url encoding:nsutf8stringencoding error:&error];
if (Error) {
NSLog (@ "%@", error);
Return
}
NSString--->NSData;
NSData *data = [str datausingencoding:nsutf8stringencoding];

NSDate-->nsstring
NSString *strdata = [[NSString alloc]initwithdata:data encoding:nsutf8stringencoding];
NSLog (@ "%@", strdata);




Nsdictionary * dict = [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutablecontainers Error:nil];
NSLog (@ "%@", dict);


NSLog (@ "str:%@", str);
}
-(void) Viewdidload {
[Super Viewdidload];


Additional setup after loading the view, typically from a nib.
}

-(void) didreceivememorywarning {
[Super didreceivememorywarning];
Dispose of any resources the can be recreated.
}

@end

Network data synchronization Request loading

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.