#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