Skip to content

Commit

Permalink
Hot Fix: Open AppStore directly rather than through SKStoreProductVie…
Browse files Browse the repository at this point in the history
…wController (#23276)
  • Loading branch information
guarani authored May 30, 2024
2 parents 8424590 + e75a1dd commit dfc41d8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 55 deletions.
3 changes: 3 additions & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
25.0
-----

24.9.1
-----
* [**] Fix bug where the option to switch to the Jetpack app is broken [#23276]

24.9
-----
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation
import StoreKit

class JetpackRedirector {

Expand Down Expand Up @@ -31,63 +30,11 @@ class JetpackRedirector {

// First, check if the WordPress app can open Jetpack by testing its URL scheme.
// if we can potentially open Jetpack app, let's open it through universal link to avoid scheme conflicts (e.g., a certain game :-).
// finally, if the user might not have Jetpack installed, open App Store view controller through StoreKit.
// finally, if the user might not have Jetpack installed, open App Store
if UIApplication.shared.canOpenURL(jetpackDeepLinkURL) {
UIApplication.shared.open(jetpackUniversalLinkURL)
} else {
showJetpackAppInstallation(fallbackURL: jetpackAppStoreURL)
UIApplication.shared.open(jetpackAppStoreURL)
}
}

private static func showJetpackAppInstallation(fallbackURL: URL) {
let viewController = RootViewCoordinator.sharedPresenter.rootViewController.topmostPresentedViewController
let storeProductVC = SKStoreProductViewController()
let appID = [SKStoreProductParameterITunesItemIdentifier: "1565481562"]

configureNavigationBarAppearance(storeProductVC)

storeProductVC.loadProduct(withParameters: appID) { (result, error) in
if result {
viewController.present(storeProductVC, animated: true)
} else if let error = error {
DDLogError("Failed loading Jetpack App product: \(error.localizedDescription)")
UIApplication.shared.open(fallbackURL)
}
}
}

// MARK: - SKStoreProductViewController navigation bar appearance

/// Sets SKStoreProductViewController navigation bar translucent
///
/// Application's global navigation appearance settings interferes with SKStoreProductViewController
/// which requires for this temporary workaround
private static func configureNavigationBarAppearance(_ controller: SKStoreProductViewController) {
let previousisTranslucentValue = UINavigationBar.appearance().isTranslucent
UINavigationBar.appearance().isTranslucent = true

/// Reset to default translucent value
storeProductViewControllerObserver = StoreProductViewControllerObserver(onDismiss: {
UINavigationBar.appearance().isTranslucent = previousisTranslucentValue
storeProductViewControllerObserver = nil
})

controller.delegate = storeProductViewControllerObserver
}

/// Observe product view controller dismissal
class StoreProductViewControllerObserver: NSObject, SKStoreProductViewControllerDelegate {
private let onDismiss: () -> ()

init(onDismiss: @escaping () -> ()) {
self.onDismiss = onDismiss
super.init()
}

func productViewControllerDidFinish(_ viewController: SKStoreProductViewController) {
onDismiss()
}
}

private static var storeProductViewControllerObserver: StoreProductViewControllerObserver?
}

0 comments on commit dfc41d8

Please sign in to comment.