iOS 应用更新机制是如何工作的?如何告知用户应用在 Appstore 上已经更新了?我是否需要在代码中编写功能来显示更新的弹出窗口,或者由 Appstore 处理以向用户显示应用已更新的通知?苹果有没有提供相关的文档说明?
iOS 应用更新机制是如何工作的?如何告知用户应用在 Appstore 上已经更新了?我是否需要在代码中编写功能来显示更新的弹出窗口,或者由 Appstore 处理以向用户显示应用已更新的通知?苹果有没有提供相关的文档说明?
例如: http://itunes.apple.com/jp/lookup/?id=1005582646
美国应用程序的示例:http://itunes.apple.com/lookup/?id=myAppIDNumberFromTheAppStore
请注意,这与App Store Connect API是分开的。如果您使用它,您需要在发出请求之前生成一个令牌。请先查阅API文档,否则您将收到空结果的响应。
https://developer.apple.com/documentation/appstoreconnectapi
https://developer.apple.com/documentation/appstoreconnectapi/generating_tokens_for_api_requests
iTunes API的响应中有一个"version"
字段,它位于"results"
字段内部。它包含了App Store上最新版本的版本号。
在AppDelegate->didFinishLaunchingWithOptions
中,你可以调用上述API。
Obj-C。
NSString *currentAppVersion = [[[NSBundle mainBundle]
infoDictionary] objectForKey:@"CFBundleShortVersionString"];
Swift (4.2)
var currentAppVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
现在,您可以比较版本号1和2,当App Store上有更新的应用程序时向用户显示警报或通知。
func viewDidLoad()
{
DispatchQueue.global().async {
do {
let update = try self.isUpdateAvailable()
DispatchQueue.main.async {
if update{
self.popupUpdateDialogue();
//you can show a popup to notify the user
}
}
} catch {
print(error)
}
}
}
func isUpdateAvailable() throws -> Bool {
guard let info = Bundle.main.infoDictionary,
let currentVersion = info["CFBundleShortVersionString"] as? String,
let identifier = info["CFBundleIdentifier"] as? String,
let url = URL(string: "http://itunes.apple.com/lookup?bundleId=\(identifier)") else {
throw VersionError.invalidBundleInfo
}
let data = try Data(contentsOf: url)
guard let json = try JSONSerialization.jsonObject(with: data, options: [.allowFragments]) as? [String: Any] else {
throw VersionError.invalidResponse
}
if let result = (json["results"] as? [Any])?.first as? [String: Any], let version = result["version"] as? String {
appStoreVersion = version
return version != currentVersion
}
throw VersionError.invalidResponse
}