2
iOS 解析短链接
source link: http://yyny.me/2017/02/09/2017-2-9-iOS%20%E8%A7%A3%E6%9E%90%E7%9F%AD%E9%93%BE%E6%8E%A5/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
iOS 解析短链接
Posted on
2017-02-09 In iOS
Tutorial
let urlString = "" // 短链接地址
let configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
/*
Tip:为了安全,最好设置下 User-Agent
let xHTTPAdditionalHeaders: [NSObject: AnyObject] = ["User-Agent": UserAgent.userAgentString]
configuration.HTTPAdditionalHeaders = xHTTPAdditionalHeaders
*/
let session = NSURLSession(configuration: configuration)
let task = session.dataTaskWithRequest(NSURLRequest(URL: scanString.urlValue!), completionHandler: { (data, response, error) in
print("短链接解析 error :\(error)")
dispatch_async(dispatch_get_main_queue(), {
if error == nil {
if let str = response?.URL?.absoluteString { // 解析后的长链接
// 成功操作
} else {
// 失败操作
}
} else {
// 失败操作
}
})
})
task.resume()
Buy me a coffee
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK