zoukankan      html  css  js  c++  java
  • 【读书笔记】iOS-GCD-用法

    代码:

     

    复制代码
    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            
            //在后台进行网址的解析操作
            NSURL * url = [NSURL URLWithString:@"http://www.baidu.com"];
            NSError * error;
            NSString * data = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error];
            if (data != nil) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    //成功。跳转回主界面
                    NSLog(@"call back, the data is: %@", data);
                });
            } else {
                //失败,返回失败提示。
                NSLog(@"error when download:%@", error);
            }
        });
        
    }
    复制代码

     

     

    输出:

    2015-07-15 21:51:37.902 CGD-使用[1719:81744] call back, the data is: <html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body style='margin:0px;overflow-x:hidden;overflow-y:hidden;'><iframe id='i' src="http://www.baidu.com/?tn=96181616_hao_pg" scrolling=auto width='100%' height='100%' frameborder='no' onload=''style='position:fixed;'></iframe></body></html>

     

     

    參考资料

    http://www.cnblogs.com/pure/archive/2013/03/31/2977420.html

     

  • 相关阅读:
    Spring Boot|Async
    SonarQube使用
    大数据|linux权限chmod和chown
    Spring Boot|监控-Actuator
    Docker|部署及简单使用
    Spring|IOC启动流程
    Spring|注解
    Spring|@Autowired与new的区别
    Spring|Spring MVC
    个人站点
  • 原文地址:https://www.cnblogs.com/lxjshuju/p/6882735.html
Copyright © 2011-2022 走看看