Skip to content

Commit

Permalink
[Customer Center] Open App Store when the user wants to update their …
Browse files Browse the repository at this point in the history
…app (#4199)
  • Loading branch information
JayShortway authored and nyeu committed Oct 1, 2024
1 parent f073ddb commit 8835a04
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ enum CustomerCenterConfigTestData {
]
),
support: .init(email: "test-support@revenuecat.com"),
lastPublishedAppVersion: lastPublishedAppVersion
lastPublishedAppVersion: lastPublishedAppVersion,
productId: 1
)
}

Expand Down
15 changes: 15 additions & 0 deletions RevenueCatUI/CustomerCenter/Views/AppUpdateWarningView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ struct AppUpdateWarningView: View {
let onUpdateAppClick: () -> Void
let onContinueAnywayClick: () -> Void

init(onUpdateAppClick: @escaping () -> Void, onContinueAnywayClick: @escaping () -> Void) {
self.onUpdateAppClick = onUpdateAppClick
self.onContinueAnywayClick = onContinueAnywayClick
}

init(productId: UInt, onContinueAnywayClick: @escaping () -> Void) {
self.init(
onUpdateAppClick: {
// productId is a positive integer, so it should be safe to construct a URL from it.
UIApplication.shared.open(URL(string: "https://itunes.apple.com/app/id\(productId)")!)
},
onContinueAnywayClick: onContinueAnywayClick
)
}

@Environment(\.localization)
private var localization: CustomerCenterConfigData.Localization
@Environment(\.appearance)
Expand Down
10 changes: 5 additions & 5 deletions RevenueCatUI/CustomerCenter/Views/CustomerCenterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,18 @@ private extension CustomerCenterView {
if viewModel.hasSubscriptions {
if viewModel.subscriptionsAreFromApple,
let screen = configuration.screens[.management] {
if ignoreAppUpdateWarning || viewModel.appIsLatestVersion {
ManageSubscriptionsView(screen: screen,
customerCenterActionHandler: viewModel.customerCenterActionHandler)
} else {
if let productId = configuration.productId, !ignoreAppUpdateWarning && !viewModel.appIsLatestVersion {
AppUpdateWarningView(
onUpdateAppClick: { viewModel.onAppUpdateClick() },
productId: productId,
onContinueAnywayClick: {
withAnimation {
ignoreAppUpdateWarning = true
}
}
)
} else {
ManageSubscriptionsView(screen: screen,
customerCenterActionHandler: viewModel.customerCenterActionHandler)
}
} else {
WrongPlatformView()
Expand Down
6 changes: 5 additions & 1 deletion Sources/CustomerCenter/CustomerCenterConfigData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,20 @@ public struct CustomerCenterConfigData {
public let localization: Localization
public let support: Support
public let lastPublishedAppVersion: String?
public let productId: UInt?

public init(screens: [Screen.ScreenType: Screen],
appearance: Appearance,
localization: Localization,
support: Support,
lastPublishedAppVersion: String?) {
lastPublishedAppVersion: String?,
productId: UInt?) {
self.screens = screens
self.appearance = appearance
self.localization = localization
self.support = support
self.lastPublishedAppVersion = lastPublishedAppVersion
self.productId = productId
}

public struct Localization {
Expand Down Expand Up @@ -345,6 +348,7 @@ extension CustomerCenterConfigData {
})
self.support = Support(from: response.customerCenter.support)
self.lastPublishedAppVersion = response.lastPublishedAppVersion
self.productId = response.itunesTrackId
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct CustomerCenterConfigResponse {

let customerCenter: CustomerCenter
let lastPublishedAppVersion: String?
let itunesTrackId: UInt?

struct CustomerCenter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class CustomerCenterConfigDataTests: TestCase {
localization: .init(locale: "en_US", localizedStrings: ["key": "value"]),
support: .init(email: "support@example.com")
),
lastPublishedAppVersion: "1.2.3"
lastPublishedAppVersion: "1.2.3",
itunesTrackId: 123
)

let configData = CustomerCenterConfigData(from: mockResponse)
Expand Down Expand Up @@ -139,6 +140,7 @@ class CustomerCenterConfigDataTests: TestCase {
}

expect(configData.lastPublishedAppVersion) == "1.2.3"
expect(configData.productId) == 123
}

}
Expand Down

0 comments on commit 8835a04

Please sign in to comment.