国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

網絡數據同步請求加載

2019-11-14 18:26:14
字體:
來源:轉載
供稿:網友

#import "ViewController.h"

@interface ViewController ()

@PRoperty(nonatomic,weak)IBOutlet UIButton *button;

@property(nonatomic,weak)IBOutlet UIImageView *imageView;


@end


@implementation ViewController

-(IBAction)btnClick:(id)sender
{
    //給一個url字符串
    NSString *str = @"http://iappfree.candou.com:8080/free/applications/limited?currency=rmb&page=3";
    
    NSString *str2 = @"http://photo.candou.com/i/114/826ea823e8ffe792a6fda9e126f6c404";
    //封裝成可用的URL類型;
    NSURL *url = [NSURL URLWithString:str];
    NSURL *url2 = [NSURL URLWithString:str2];
    
    [self syncDownloadWithString:url];
    [self syncDownloadWithData:url2];
}

#pragma mark -NSDate類方法的同步請求-

-(void)syncDownloadWithData:(NSURL *)url{
    //二進制數據提供的同步請求方法
    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(@"下載完畢");
}

#pragma mark -NSString類方法的同步請求-
-(void)syncDownloadWithString:(NSURL *)url{

    //字符串提供的同步請求的方法
    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];
    

    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 读书| 松江区| 元朗区| 武定县| 长春市| 武强县| 望谟县| 木里| 沈丘县| 资兴市| 蓬溪县| 普兰县| 彭州市| 南昌县| 扎鲁特旗| 玉溪市| 赫章县| 汶川县| 正安县| 印江| 东港市| 瓮安县| 盘山县| 囊谦县| 宝应县| 怀化市| 合川市| 鹤庆县| 九龙县| 汝城县| 新乡县| 新沂市| 乐安县| 邯郸市| 宜宾县| 商都县| 山东省| 建宁县| 洪江市| 临邑县| 华坪县|