Swift   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了swift 解析GZIP大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

居然会自动解码,要不要这么智能,弄了快一个上午,傻逼了。。。。 1、如果不能自动解析的话,就得用http://stackoverflow.com/questions/29694050/gzip-usage-in-swift  using this NSData+GZIP.swift library to zip/unzip data from server and here is process

居然会自动解码,要不要这么智能,弄了快一个上午,傻逼了。。。。


1、如果不能自动解析的话,就得用http://stackoverflow.com/questions/29694050/gzip-usage-in-swift

using thisNSData+GZIP.swiftlibrary to zip/unzip data from server and here is process how to use it:

  1. AddNSData+GZIP.swiftfile to your project.
  2. Addlibz.dyliblibrary to your project.
  3. Add a line#include <zlib.h>to yourProjectName-Bridging-Header.hfile.
  4. Invoke from your Swift/ObjC files.
提问题的人设置的方法是对的,不过他的 ProjectName-Bridging-Header.h设置出错


2、如果你和我情况一样,加一行代码就搞定了:

request.addValue("Accept-Encoding",forHTTPHeaderField:"gzip")

其他系统会自动解析,以前怎么用,现在也怎么用。


例如:

let request :NSMutableURLRequest = NSMutableURLRequest(URL: URL,cachePolicy: NSURLRequestCachePolicy.UseProtocolCachePolicy,timeoutInterval: 40)
request.HTTPMethod = "GET"
request.addValue("Accept-Encoding",forHTTPHeaderField: "gzip")

NSURLConnection.sendAsynchronousRequest(request,queue: NSOperationQueue.mainQueue(),completionHandler:
{(response :NSURLResponse?,data: NSData?,error: NSError?) -> Void in
    callback(error,data)
})

大佬总结

以上是大佬教程为你收集整理的swift 解析GZIP全部内容,希望文章能够帮你解决swift 解析GZIP所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: