Updates repo is not able to redirect to the App Store for updating
keegho opened this issue · 3 comments
I have installed Updates using Cocoapods
and it was working fine at the beginning. Now I'm testing and Bulding with an older version number 1.0.9 and what we have in store is 1.0.10 it not working anymore. The result is correct that there is an update available and the message is being displayed. But when I tap update it goes no where. After debugging in the library code I have found out that Updates.appStoreId
is nil for some weird reason.
Here is where the issue occurs in the code. It couldn't pass the guard statement. And it returns.
/// Presents SKStoreProductViewController modally.
public func presentAppStore(animated: Bool = true, completion: (() -> Void)? = nil,
presentingViewController: UIViewController) {
guard let appStoreId = Updates.appStoreId, let appStoreIdentifierInt = UInt(appStoreId) else {
return
}
let animated = self.animated
let appStoreIdentifier: NSNumber = NSNumber(value: appStoreIdentifierInt)
let parameters = [SKStoreProductParameterITunesItemIdentifier: appStoreIdentifier]
let viewController = SKStoreProductViewController()
viewController.delegate = self
viewController.loadProduct(withParameters: parameters) { [weak self] (loadedSuccessfully, error) in
if !loadedSuccessfully, let appStoreURL = Updates.appStoreURL {
print(error as Any)
self?.presentSafariViewController(animated: animated,
presentingViewController: presentingViewController,
url: appStoreURL)
}
}
DispatchQueue.main.async {
presentingViewController.present(viewController, animated: animated, completion: nil)
}
}
This is my code:
private func checkForUpdate() {
Updates.configurationURL = URL(imagePath: "/updates_versions.json") //Bundle.main.url(forResource: "Updates", withExtension: "json")
Updates.checkForUpdates { result in
print("UPDATE RESULT:", result)
Updates.countryCode = Locale.current.regionCode
guard case let .available(update) = result else {
self.checkClientToken()
return
}
if update.shouldNotify {
var alertTitle = ""
let alertMessage: String? = update.releaseNotes
if let productName = Updates.productName {
alertTitle = "\(productName) v\(update.newVersionString) Available"
} else {
alertTitle = "Version \(update.newVersionString) Available"
}
AlertView.shared.showAlert(title: alertTitle, message: alertMessage ?? "", type: .update, buttonTwoTitle: Localized("Cancel")) {
self.checkClientToken()
} buttonOneAction: {
print("APP STORE ID:", Updates.appStoreId ?? "NIL")
print("APP STORE URL:", Updates.appStoreURL ?? "NIL")
UpdatesUI.presentAppStore(animated: true, completion: nil,
presentingViewController: self)
}
}
}
}
I tried also using the normal default not the customized way and no use.
UpdatesUI.promptToUpdate(result, presentingViewController: self)
Hello I fixed it by adding this
Updates.appStoreId = "xxxxxxxxxx"
in the code. Can i also add it in the json when using the automatic way?
@keegho Sorry for the delay in getting back to you. When set to automatic the Updates framework looks up the App Store identifier for you - you can set the App Store Id in the JSON when set to manual rather than automatic.
The thing to look at is why the framework is failing to return the App Store Id for you in this case. Things worth checking are:
- Is the bundle identifier correct for the app you want to look up in the store - if your build has a different bundle id to the one in the App Store (e.g. in a test build) the framework won't be able to retrieve the relevant information
- Is the country code correct? The framework uses this to look up your app in the relevant App Store territory however if there is a mismatch here this can sometimes result in no information being retrieved
- One more thing to check is what notify value you have used. If the framework is configured to notify the user about an update only once and it has already done so then you won't be presented with the update again. I usually test this by clearing the iOS simulator and running a clean install.
Hope some of this helps!