ios应用的应用内更新,无需重定向到应用商店或itunes
下面的代码将我重定向到应用商店,但这不应该发生。应用程序应在应用程序内得到更新,而无需重定向到应用程序商店或itunes。 //用于检查应用程序版本的函数ios应用的应用内更新,无需重定向到应用商店或itunes,ios,swift,Ios,Swift,下面的代码将我重定向到应用商店,但这不应该发生。应用程序应在应用程序内得到更新,而无需重定向到应用程序商店或itunes。 //用于检查应用程序版本的函数 func isUpdateAvailable() throws -> Bool { guard let info = Bundle.main.infoDictionary, let currentVersion = info["CFBundl
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应用程序无法从应用程序本身内部更新,只能通过应用程序商店更新。作为一名开发人员,无论您的用户是否更新应用程序,您都没有发言权或控制权。没有通过一些内部逻辑阻止他们使用它
有一些先进的技术允许您更新应用程序业务逻辑的某些方面,但这超出了这个问题的范围。您认为为什么不应该这样做?如果它将你重定向到app store,它的工作方式与它应该的工作方式完全相同。无法通过编程启动应用程序的“引擎盖下”/“后台更新”。用户必须点击应用商店中的“更新”,或者启用“自动更新”,然后等待iOS获取并安装更新。嗨,EarlGrey,谢谢你的回答。通过你的回答,我知道在应用程序中更新应用程序是不可能的。但是,您能告诉我哪些高级技术可以用来更新应用程序的业务逻辑吗?这对于评论回答来说太复杂了,但是可以随意创建一个新的问题来询问这个问题。也许你会有一些好主意。如果我的回答对你有帮助,也请接受。非常感谢。