获取App在AppStore的版本信息问题

写在前面

在使用"itunes.apple.com/lookup?bund... 请求苹果商店的App信息时,获取到的版本号(version)是以前的版本号,单独使用这个地址从网页中获取到的数据是正确的,但是在项目中使用代码获取到的版本号就落后了一个版本。

上代码

以下是我的请求App信息的代码,此代码请求的数据不是实时的,版本号落后了一个版本,其它信息是正确的:

Swift 复制代码
public class func versionAndDownloadUrl() -> (version: String, downloadUrl: String)? {
    guard let identifier = Bundle.main.object(forInfoDictionaryKey: "CFBundleIdentifier") as? String, 
    let url = URL(string: "http://itunes.apple.com/lookup?bundleId=\(identifier)") 
    else { 
        return nil
    }

    guard let data = try? Data(contentsOf: url),
    let json = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any],
    let results = json["results"] as? [[String: Any]],
    results.count > 0,
    let version = results[0]["version"] as? String,
    let downLoadUrl = results[0]["trackViewUrl"] as? String
    else {
     return nil
    }
    return (version, downLoadUrl)
    }

需要把此处的请求地址加上时间戳才能获取到正确的App信息

正确的请求URL地址

swift 复制代码
let url = URL(string: "http://itunes.apple.com/lookup?bundleId=\(identifier)&date=\(Date.init().timeIntervalSince1970)")

替换上面代码里面的URL地址即可请求到最新的App信息。

资料来自:https://forums.developer.apple.com/forums/thread/125461

在URL地址中加入时间戳可能不是最好的解决方法,但确实能解决该问题,如果你有更好的解决方法,请不吝赐教!

相关推荐
eleven40964 天前
穿透内容审查与阻断:基于 DNS TXT 记录的动态服务发现与客户端安全加固实践
网络协议·ios·app
私人珍藏库4 天前
[Android] 亿连车机版V7.0.1
android·app·软件·车机
sp424 天前
NativeScript iOS 平台开发技巧
app·nativescript
sp424 天前
NativeScript 开发技巧
app·nativescript
sp424 天前
在 NativeScript-Vue 中实现流畅的共享元素转场动画
app·nativescript
sp424 天前
在 NativeScript 中扩展 Android 原生类
app·nativescript
Kingexpand_com7 天前
任务分发管理APP开发全解析|技术选型、架构设计与落地实践(旌展技术分享)
app·软件开发·app开发·app定制开发·app定制开发公司
Kingexpand_com9 天前
物联网APP开发实战:如何打造用户真正愿意用的智能硬件伴侣
物联网·小程序·app·智能硬件·物联网app定制开发
summerkissyou198711 天前
Android-view-绘制流程及自定义例子
android·app
aykon18 天前
SparseArray详解,SparseArray和HashMap性能、内存对比
app