适用于ios应用程序的应用内更新,无需重定向到应用商店或itunes



下面的代码将我重定向到应用商店,但这不应该发生。应用程序应在应用程序内进行更新,而无需重定向到应用程序商店或itunes。//用于检查应用程序版本的功能

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/in/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 {
print("version in app store", version,currentVersion);
return version != currentVersion
}
throw VersionError.invalidResponse
}
// Function to show alert for 
func popuplateAppUpdateDialogue(in vc: UIViewController,
title: String?,
message: String,
for appleId: String){
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
let updateBtn = UIAlertAction(title: "Update", style: .default) { (_) in
AppUtils.shared.openAppOnAppStore(appleId: appleId)
}
// Below is the AppUtils function which I used in my code
func openAppOnAppStore(appleId: String){
let appStoreLink: String = "itms-apps://itunes.apple.com/app/id(appleId)"
if let url = URL(string: appStoreLink) {
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil
} else {
// Earlier versions
if UIApplication.shared.canOpenURL(url as URL) {
UIApplication.shared.openURL(url as URL)
}
}
}
}

完整的iOS应用程序不能从应用程序本身更新,只能通过应用商店更新。此外,作为开发人员,无论用户是否更新应用程序,您都没有发言权或控制权。除了通过某种内部逻辑阻止他们使用它之外。

有一些高级技术允许您更新应用程序业务逻辑的某些方面,但这超出了本问题的范围。

最新更新