美文网首页
iOS编程网址链接总结

iOS编程网址链接总结

作者: 动机至善私心了无 | 来源:发表于2016-11-10 13:48 被阅读33次
    1. iOS开发中实现国际化语言切换:http://blog.csdn.net/sinat_33178727/article/details/52226230

    2.iOS开发的22个奇谲巧技: http://blog.csdn.net/skykingf/article/details/42246511

    3.半小时学会上传本地项目到github: http://www.cocoachina.com/ios/20160212/15024.html

    4.JSCore的基本使用:
    http://www.cocoachina.com/ios/20161117/18117.html

    5.优化APP时发现的SDWebImage的问题
    http://www.tuicool.com/articles/AJbuqaf

    6.禅与 Objective-C 编程艺术 :
    https://www.gitbook.com/book/yourtion/objc-zen-book-cn/details

    7.Xcode常见错误链接地址:
    http://blog.csdn.net/poleness/article/details/27977637

    8.使用 ASDK 性能调优 - 提升 iOS 界面的渲染性能
    https://github.com/Draveness/analyze/blob/master/contents/AsyncDisplayKit/提升%20iOS%20界面的渲染性能%20.md#使用-asdk-性能调优---提升-ios-界面的渲染性能

    
    
    #import "HWHttpTool.h"
    #import "MBProgressHUD.h"
    
    
    @implementation HWHttpTool
    
    + (void)get:(NSString *)url params:(NSDictionary *)params success:(void (^)(id json))success failure:(void (^)(NSError *error))failure
    {
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    //    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
        manager.responseSerializer.acceptableContentTypes = nil;
        
    //    manager.securityPolicy.allowInvalidCertificates = NO;
        [manager GET:url parameters:params progress:^(NSProgress * _Nonnull downloadProgress) {
            
        }
             success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                 
                success(responseObject);
                 
             }
         
             failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull   error) {
                failure(error);  //这里打印错误信息
             }];
      
    }
    
    + (void)post:(NSString *)url params:(NSDictionary *)params success:(void (^)(id json))success failure:(void (^)(NSError *error))failure
    {
        
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/html", nil];
        [manager setSecurityPolicy:[self customSecurityPolicy]];
        manager.requestSerializer.timeoutInterval = 20;
        [manager POST:url parameters:params progress:^(NSProgress * _Nonnull uploadProgress){
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
             success(responseObject);
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            failure(error);
        }];
    
    }
    
    //+ (void)getJson:(NSString *)url params:(NSDictionary *)params success:(void (^)(id json))success failure:(void (^)(NSError *error))failure{
    //    
    //    // 1.创建请求管理者
    //    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    //    mgr.requestSerializer=[AFJSONRequestSerializer serializer];
    //    mgr.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/html", nil];
    //    // 2.发送请求GET
    //    [mgr GET:url parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
    //        if (success) {
    //            success(responseObject);
    //        }
    //    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    //        if (failure) {
    //            failure(error);
    //        }
    //    }];
    //}
    
    //带图层指示框的get请求
    + (void)getWithHUD:(UIView *)view WithUrl:(NSString *)url params:(NSDictionary *)params success:(void (^)(id json))success failure:(void (^)(NSError *error))failure
    {
        [MBProgressHUD showHUDAddedTo:view animated:YES];
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        [manager GET:url parameters:params progress:^(NSProgress * _Nonnull downloadProgress) {
            
        }
             success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                  [MBProgressHUD hideHUDForView:view animated:YES];
                 success(responseObject);
                 
             }
         
             failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull   error) {
                  [MBProgressHUD hideHUDForView:view animated:YES];
                 failure(error);  //这里打印错误信息
             }];
    }
    
    //带图层指示框的post请求
    + (void)postWithHUD:(UIView *)view WithUrl:(NSString *)url params:(NSDictionary *)params success:(void (^)(id json))success failure:(void (^)(NSError *error))failure{
        [MBProgressHUD showHUDAddedTo:view animated:YES];
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        [manager POST:url parameters:params progress:^(NSProgress * _Nonnull uploadProgress){
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
             [MBProgressHUD hideHUDForView:view animated:YES];
            success(responseObject);
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
             [MBProgressHUD hideHUDForView:view animated:YES];
            failure(error);
        }];
    }
    //+ (void)postJson:(NSString *)url params:(NSDictionary *)params success:(void (^)(id json))success failure:(void (^)(NSError *error))failure
    //{
    //    // 1.创建请求管理者
    //    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    //    mgr.requestSerializer=[AFJSONRequestSerializer serializer];
    //    mgr.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/html", nil];
    //    // 2.发送请求
    //    [mgr POST:url parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
    //        if (success) {
    //            success(responseObject);
    //        }
    //    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    //        if (failure) {
    //            failure(error);
    //        }
    //    }];
    //}
    
    //文件上传(图片)
    + (void)post:(NSString *)url params:(NSDictionary *)params fileDatas:(NSArray *)fileDatas name:(NSString *)name fileNames:(NSArray *)fileNames mimeTypes:(NSArray *)mineTypes success:(void (^)(id json))success failure:(void (^)(NSError *error))failure{
        
        //1。创建管理者对象
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        
        //2.上传文件
    //    NSDictionary *dict = @{@"username":@"1234"};
    //    
    //    NSString *urlString = @"22222";
        [manager POST:url parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
            //上传文件参数
    //        UIImage *iamge = [UIImage imageNamed:@"123.png"];
    //        NSData *data = UIImagePNGRepresentation(iamge);
    //        //这个就是参数
    //        [formData appendPartWithFileData:data name:@"file" fileName:@"123.png" mimeType:@"image/png"];
            if (fileDatas.count == fileNames.count && fileNames.count == mineTypes.count) {
                for (int i = 0; i < fileDatas.count; i ++) {
                    [formData appendPartWithFileData:fileDatas[i] name:name fileName:fileNames[i] mimeType:mineTypes[i]];
                }
            }
            
        } progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            success(responseObject);
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
            failure(error);
        }];
        
    }
    
    //文件下载
    + (void)downloadTaskWithURL:(NSString *)urlstr  progress:(void (^)(NSProgress *downloadProgress)) downloadProgressBlock completionHandler:(void (^)(NSURLResponse *response, NSURL *filePath, NSError *error))completionHandler{
        
        //1.创建管理者对象
        AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        
        //3.创建请求对象
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlstr]];
        //下载任务
        NSURLSessionDownloadTask *task = [manager downloadTaskWithRequest:request progress:^(NSProgress * _Nonnull downloadProgress)
        {
            downloadProgressBlock(downloadProgress);
            
        } destination:^NSURL * _Nonnull(NSURL * _Nonnull targetPath, NSURLResponse * _Nonnull response)
        {
    //        NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
    //        
    //        return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]];
    //        
    //        //下载地址
    //        WKNSLog(@"默认下载地址:%@",targetPath);
            
            //设置下载路径,通过沙盒获取缓存地址,最后返回NSURL对象
            NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
            return [NSURL URLWithString:filePath];
            
            
        } completionHandler:^(NSURLResponse * _Nonnull response, NSURL * _Nullable filePath, NSError * _Nullable error)
                                          {
           completionHandler(response,filePath,error);
            
        }];
        //开始启动任务
        [task resume];
        
    }
    
    
    + (AFSecurityPolicy *)customSecurityPolicy {
        // 先导入证书 证书由服务端生成,具体由服务端人员操作
        NSString *cerPath = [[NSBundle mainBundle] pathForResource:@"2_www.guaigunwang.com" ofType:@"cer"];//证书的路径
        NSData *cerData = [NSData dataWithContentsOfFile:cerPath];
        
        // AFSSLPinningModeCertificate 使用证书验证模式
        AFSecurityPolicy *securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
        // allowInvalidCertificates 是否允许无效证书(也就是自建的证书),默认为NO
        // 如果是需要验证自建证书,需要设置为YES
        securityPolicy.allowInvalidCertificates = YES;
        
        //validatesDomainName 是否需要验证域名,默认为YES;
        //假如证书的域名与你请求的域名不一致,需把该项设置为NO;如设成NO的话,即服务器使用其他可信任机构颁发的证书,也可以建立连接,这个非常危险,建议打开。
        //置为NO,主要用于这种情况:客户端请求的是子域名,而证书上的是另外一个域名。因为SSL证书上的域名是独立的,假如证书上注册的域名是www.google.com,那么mail.google.com是无法验证通过的;当然,有钱可以注册通配符的域名*.google.com,但这个还是比较贵的。
        //如置为NO,建议自己添加对应域名的校验逻辑。
        securityPolicy.validatesDomainName = NO;
        
        securityPolicy.pinnedCertificates = [[NSSet alloc] initWithObjects:cerData,nil];
        
        return securityPolicy;
    }
    
    @end
    
    
    
    
    -(void)webViewDidFinishLoad:(UIWebView *)webView
    {
        webView.scrollView.bounces=NO;
        NSString * clenitHeight_str=[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"];
        float cilentHeig=[clenitHeight_str floatValue];
        webView.frame=CGRectMake(0, webViewOry, self.view.frame.size.width, cilentHeig);
        CGSize frame=[webView sizeThatFits:webView.frame.size];
        
        NSString * js = [NSString stringWithFormat:@"var images = document.getElementsByTagName('img'); for(var i = 0; i < images.length; i++){images[i].width = %f;}", webView.frame.size.width - 15];
        [webView stringByEvaluatingJavaScriptFromString:js];
        NSString *js_fit_code = [NSString stringWithFormat:@"var meta = document.createElement('meta');"
                                 "meta.name = 'viewport';"
                                 "meta.content = 'width=device-width, initial-scale=1.0,minimum-scale=0.1, maximum-scale=2.0, user-scalable=yes';"
                                 "document.getElementsByTagName('head')[0].appendChild(meta);"
                                 ];
        [webView stringByEvaluatingJavaScriptFromString:js_fit_code];
        //获取内容实际高度(像素)
        
        NSString * height_str= [webView stringByEvaluatingJavaScriptFromString: @"document.getElementById('webview_content_wrapper').offsetHeight + parseInt(window.getComputedStyle(document.getElementsByTagName('body')[0]).getPropertyValue('margin-top'))  + parseInt(window.getComputedStyle(document.getElementsByTagName('body')[0]).getPropertyValue('margin-bottom'))"];
        
        float height = [height_str floatValue];
        //内容实际高度(像素)* 点和像素的比
        height = height * frame.height/cilentHeig;
        //再次设置WebView高度(点)
        webView.height=height;
        [webView setScalesPageToFit:YES];
        self.wenxinView.height=height+45/568.0 * HEIGHT;
        scrollView.contentSize = CGSizeMake(WIDTH, CGRectGetMaxY(_wenxinView.frame));
    }
    

    相关文章

      网友评论

          本文标题:iOS编程网址链接总结

          本文链接:https://www.haomeiwen.com/subject/vacxpttx.html