From ce316993753ff591c1047df454b1a9ff9eda39a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Fern=C3=A1ndez?= Date: Sat, 15 Oct 2022 18:20:08 +0200 Subject: [PATCH 1/2] feat(UpdateAvailableInsight): user defined App Store region --- Sources/DiagnosticsReporter.swift | 8 +++++--- Sources/Reporters/SmartInsightsReporter.swift | 4 ++-- Sources/SmartInsights/UpdateAvailableInsight.swift | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Sources/DiagnosticsReporter.swift b/Sources/DiagnosticsReporter.swift index c1c3e91..14969da 100644 --- a/Sources/DiagnosticsReporter.swift +++ b/Sources/DiagnosticsReporter.swift @@ -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: @@ -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 @@ -79,7 +81,7 @@ 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) @@ -87,7 +89,7 @@ public enum DiagnosticsReporter { 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) } } diff --git a/Sources/Reporters/SmartInsightsReporter.swift b/Sources/Reporters/SmartInsightsReporter.swift index 2f82d89..6c48aba 100644 --- a/Sources/Reporters/SmartInsightsReporter.swift +++ b/Sources/Reporters/SmartInsightsReporter.swift @@ -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()) diff --git a/Sources/SmartInsights/UpdateAvailableInsight.swift b/Sources/SmartInsights/UpdateAvailableInsight.swift index 0513563..b2b0936 100644 --- a/Sources/SmartInsights/UpdateAvailableInsight.swift +++ b/Sources/SmartInsights/UpdateAvailableInsight.swift @@ -27,10 +27,11 @@ struct UpdateAvailableInsight: SmartInsightProviding { init?( bundleIdentifier: String? = Bundle.main.bundleIdentifier, currentVersion: String = Bundle.appVersion, - appMetadataPublisher: AnyPublisher? = nil + appMetadataPublisher: AnyPublisher? = 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() From 0632a7893bc3d38a17d33ac06b2ae7f4f04a0f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Fern=C3=A1ndez?= Date: Mon, 17 Oct 2022 14:32:01 +0200 Subject: [PATCH 2/2] update to use device region as itunes region --- Sources/DiagnosticsReporter.swift | 5 ++--- Sources/Reporters/SmartInsightsReporter.swift | 4 ++-- Sources/SmartInsights/UpdateAvailableInsight.swift | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Sources/DiagnosticsReporter.swift b/Sources/DiagnosticsReporter.swift index 14969da..a461e6b 100644 --- a/Sources/DiagnosticsReporter.swift +++ b/Sources/DiagnosticsReporter.swift @@ -30,7 +30,7 @@ public enum DiagnosticsReporter { case .appSystemMetadata: return AppSystemMetadataReporter() case .smartInsights: - return SmartInsightsReporter(itunesRegion: "us") + return SmartInsightsReporter() case .logs: return LogsReporter() case .userDefaults: @@ -54,7 +54,6 @@ public enum DiagnosticsReporter { /// - 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 @@ -81,7 +80,7 @@ public enum DiagnosticsReporter { } if let smartInsightsChapterIndex = reporters.firstIndex(where: { $0 is SmartInsightsReporter }) { - var smartInsightsReporter = SmartInsightsReporter(itunesRegion: itunesRegion) + var smartInsightsReporter = SmartInsightsReporter() smartInsightsReporter.insights.append(contentsOf: smartInsights) let smartInsightsChapter = smartInsightsReporter.report() reportChapters.insert(smartInsightsChapter, at: smartInsightsChapterIndex) diff --git a/Sources/Reporters/SmartInsightsReporter.swift b/Sources/Reporters/SmartInsightsReporter.swift index 6c48aba..2f82d89 100644 --- a/Sources/Reporters/SmartInsightsReporter.swift +++ b/Sources/Reporters/SmartInsightsReporter.swift @@ -40,10 +40,10 @@ public struct SmartInsightsReporter: DiagnosticsReporting { let title: String = "Smart Insights" var insights: [SmartInsightProviding] - init(itunesRegion: String = "us") { + init() { var defaultInsights: [SmartInsightProviding?] = [ DeviceStorageInsight(), - UpdateAvailableInsight(itunesRegion: itunesRegion) + UpdateAvailableInsight() ] #if os(iOS) && !targetEnvironment(macCatalyst) defaultInsights.append(CellularAllowedInsight()) diff --git a/Sources/SmartInsights/UpdateAvailableInsight.swift b/Sources/SmartInsights/UpdateAvailableInsight.swift index b2b0936..0332d4c 100644 --- a/Sources/SmartInsights/UpdateAvailableInsight.swift +++ b/Sources/SmartInsights/UpdateAvailableInsight.swift @@ -28,7 +28,7 @@ struct UpdateAvailableInsight: SmartInsightProviding { bundleIdentifier: String? = Bundle.main.bundleIdentifier, currentVersion: String = Bundle.appVersion, appMetadataPublisher: AnyPublisher? = nil, - itunesRegion: String = "us" + itunesRegion: String = Locale.current.regionCode ?? "us" ) { guard let bundleIdentifier = bundleIdentifier else { return nil } let url = URL(string: "https://itunes.apple.com/\(itunesRegion)/lookup?bundleId=\(bundleIdentifier)")!