Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let developer set App Store region for UpdateAvailableInsight #133

Merged
merged 2 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Sources/DiagnosticsReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public enum DiagnosticsReporter {
case .appSystemMetadata:
return AppSystemMetadataReporter()
case .smartInsights:
return SmartInsightsReporter()
return SmartInsightsReporter(itunesRegion: "us")
case .logs:
return LogsReporter()
case .userDefaults:
Expand All @@ -53,6 +53,8 @@ public enum DiagnosticsReporter {
/// - filters: The filters to use for the generated diagnostics. Should conform to the `DiagnosticsReportFilter` protocol.
/// - smartInsightsProvider: Provide any smart insights for the given `DiagnosticsChapter`.
public static func create(
filename: String = "Diagnostics-Report.html",
itunesRegion: String = "us",
using reporters: [DiagnosticsReporting] = DefaultReporter.allReporters,
filters: [DiagnosticsReportFilter.Type]? = nil,
smartInsightsProvider: SmartInsightsProviding? = nil
Expand All @@ -79,15 +81,15 @@ public enum DiagnosticsReporter {
}

if let smartInsightsChapterIndex = reporters.firstIndex(where: { $0 is SmartInsightsReporter }) {
var smartInsightsReporter = SmartInsightsReporter()
var smartInsightsReporter = SmartInsightsReporter(itunesRegion: itunesRegion)
smartInsightsReporter.insights.append(contentsOf: smartInsights)
let smartInsightsChapter = smartInsightsReporter.report()
reportChapters.insert(smartInsightsChapter, at: smartInsightsChapterIndex)
}

let html = generateHTML(using: reportChapters)
let data = html.data(using: .utf8)!
return DiagnosticsReport(filename: "Diagnostics-Report.html", data: data)
return DiagnosticsReport(filename: filename, data: data)
}
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Reporters/SmartInsightsReporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public struct SmartInsightsReporter: DiagnosticsReporting {
let title: String = "Smart Insights"
var insights: [SmartInsightProviding]

init() {
init(itunesRegion: String = "us") {
var defaultInsights: [SmartInsightProviding?] = [
DeviceStorageInsight(),
UpdateAvailableInsight()
UpdateAvailableInsight(itunesRegion: itunesRegion)
]
#if os(iOS) && !targetEnvironment(macCatalyst)
defaultInsights.append(CellularAllowedInsight())
Expand Down
5 changes: 3 additions & 2 deletions Sources/SmartInsights/UpdateAvailableInsight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ struct UpdateAvailableInsight: SmartInsightProviding {
init?(
bundleIdentifier: String? = Bundle.main.bundleIdentifier,
currentVersion: String = Bundle.appVersion,
appMetadataPublisher: AnyPublisher<AppMetadataResults, Error>? = nil
appMetadataPublisher: AnyPublisher<AppMetadataResults, Error>? = nil,
itunesRegion: String = "us"
) {
guard let bundleIdentifier = bundleIdentifier else { return nil }
let url = URL(string: "https://itunes.apple.com/br/lookup?bundleId=\(bundleIdentifier)")!
let url = URL(string: "https://itunes.apple.com/\(itunesRegion)/lookup?bundleId=\(bundleIdentifier)")!

let group = DispatchGroup()
group.enter()
Expand Down