|
1 | 1 | import Foundation |
2 | | -import StoreKit |
3 | 2 |
|
4 | 3 | class JetpackRedirector { |
5 | 4 |
|
@@ -31,63 +30,11 @@ class JetpackRedirector { |
31 | 30 |
|
32 | 31 | // First, check if the WordPress app can open Jetpack by testing its URL scheme. |
33 | 32 | // if we can potentially open Jetpack app, let's open it through universal link to avoid scheme conflicts (e.g., a certain game :-). |
34 | | - // finally, if the user might not have Jetpack installed, open App Store view controller through StoreKit. |
| 33 | + // finally, if the user might not have Jetpack installed, open App Store |
35 | 34 | if UIApplication.shared.canOpenURL(jetpackDeepLinkURL) { |
36 | 35 | UIApplication.shared.open(jetpackUniversalLinkURL) |
37 | 36 | } else { |
38 | | - showJetpackAppInstallation(fallbackURL: jetpackAppStoreURL) |
| 37 | + UIApplication.shared.open(jetpackAppStoreURL) |
39 | 38 | } |
40 | 39 | } |
41 | | - |
42 | | - private static func showJetpackAppInstallation(fallbackURL: URL) { |
43 | | - let viewController = RootViewCoordinator.sharedPresenter.rootViewController.topmostPresentedViewController |
44 | | - let storeProductVC = SKStoreProductViewController() |
45 | | - let appID = [SKStoreProductParameterITunesItemIdentifier: "1565481562"] |
46 | | - |
47 | | - configureNavigationBarAppearance(storeProductVC) |
48 | | - |
49 | | - storeProductVC.loadProduct(withParameters: appID) { (result, error) in |
50 | | - if result { |
51 | | - viewController.present(storeProductVC, animated: true) |
52 | | - } else if let error = error { |
53 | | - DDLogError("Failed loading Jetpack App product: \(error.localizedDescription)") |
54 | | - UIApplication.shared.open(fallbackURL) |
55 | | - } |
56 | | - } |
57 | | - } |
58 | | - |
59 | | - // MARK: - SKStoreProductViewController navigation bar appearance |
60 | | - |
61 | | - /// Sets SKStoreProductViewController navigation bar translucent |
62 | | - /// |
63 | | - /// Application's global navigation appearance settings interferes with SKStoreProductViewController |
64 | | - /// which requires for this temporary workaround |
65 | | - private static func configureNavigationBarAppearance(_ controller: SKStoreProductViewController) { |
66 | | - let previousisTranslucentValue = UINavigationBar.appearance().isTranslucent |
67 | | - UINavigationBar.appearance().isTranslucent = true |
68 | | - |
69 | | - /// Reset to default translucent value |
70 | | - storeProductViewControllerObserver = StoreProductViewControllerObserver(onDismiss: { |
71 | | - UINavigationBar.appearance().isTranslucent = previousisTranslucentValue |
72 | | - storeProductViewControllerObserver = nil |
73 | | - }) |
74 | | - |
75 | | - controller.delegate = storeProductViewControllerObserver |
76 | | - } |
77 | | - |
78 | | - /// Observe product view controller dismissal |
79 | | - class StoreProductViewControllerObserver: NSObject, SKStoreProductViewControllerDelegate { |
80 | | - private let onDismiss: () -> () |
81 | | - |
82 | | - init(onDismiss: @escaping () -> ()) { |
83 | | - self.onDismiss = onDismiss |
84 | | - super.init() |
85 | | - } |
86 | | - |
87 | | - func productViewControllerDidFinish(_ viewController: SKStoreProductViewController) { |
88 | | - onDismiss() |
89 | | - } |
90 | | - } |
91 | | - |
92 | | - private static var storeProductViewControllerObserver: StoreProductViewControllerObserver? |
93 | 40 | } |
0 commit comments