INNER CODE UNIT · Swift
getInfoFromAppStore
rhymelph/r_upgrade · ios/Classes/SwiftRUpgradePlugin.swift:83
func getInfoFromAppStore(appId:String,isChina:Bool,complete:@escaping(_ result:NSDictionary?)->Void,error:@escaping(_ error:Error?)->Void) {
let checkLink = isChina == true ? "https://itunes.apple.com/cn/lookup?id=" : "https://itunes.apple.com/lookup?id="
let appUrl = checkLink + appId
let url = NSURL(string: appUrl)! as URL
let request = NSMutableURLRequest(url: url, cachePolicy: NSURLRequest.CachePolicy.reloadIgnoringLocalCacheData, timeoutInterval: 30)
request.httpMethod = "GET"
let session = URLSession.shared
let task = session.dataTask(with: request as URLRequest){(data,response,err) in
if err == nil{
if data == nil{
NSLog("获取appId:%@ 对应的appStore信息失败",appId)
complete(nil)
}
let httpRequest = response as! HTTPURLResponse
if httpRequest.statusCode == 200 {
let json = try! JSONSerialization.jsonObject(with: data! as Data, options: JSONSerialization.ReadingOptions.mutableLeaves) as! NSDictionary