首页 > 代码库 > swift使用ASIHttpRequest
swift使用ASIHttpRequest
- 添加第三方库ASIHttpRequest
- 添加SystemConfiguration.framework, MobileCoreServices.framework,CoreGraphics.framework和libz.1.2.3.dylib类库
- 在Build Phases --> Compile Source 中将.m文件的Compiler Flags添加 -fno-objc-arc标识
- 在swift和objective-c的桥接文件中插入 #import"ASIHTTPRequest.h"
- 编写访问后台的代码
class ServerManager: NSObject, ASIHTTPRequestDelegate{ var server = "http://192.168.0.101:3001" func getMagazineList()->NSDictionary?{ var url = NSURL(string: NSString(format: "%@/magazine/list", server)) var request = ASIHTTPRequest(URL: url) request.startSynchronous() var requestError = request.error var requestData: NSDictionary? if(requestError == nil){ requestData = request.responseString().objectFromJSONString() as? NSDictionary }else{ println("\(requestError)") } return requestData } func getMagazine() -> NSDictionary?{ var url = NSURL(string: NSString(format: "%@/magazine/info", server)) var request = ASIHTTPRequest(URL: url) request.startSynchronous() var requestError = request.error var requestData:NSDictionary? if(requestError == nil){ requestData = request.responseString().objectFromJSONString() as? NSDictionary }else{ println("\(requestError)") } return requestData } }
swift使用ASIHttpRequest
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。