From 14284bf66894d6ede2ee7c3d13e3882a87d99bcc Mon Sep 17 00:00:00 2001 From: iHTCboy Date: Tue, 25 Apr 2023 19:02:54 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9Asearch=20for=20apps=20through=20ap?= =?UTF-8?q?p=20id=20or=20package=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iAppStore.xcodeproj/project.pbxproj | 14 +++++------- iAppStore/Network/APIService.swift | 6 +++-- iAppStore/Shared/UI/LoadingView.swift | 2 +- iAppStore/ViewModels/AppDetailModel.swift | 22 +++++++++++++++++++ .../rankLists/AppDetailContentView.swift | 2 +- .../components/rankLists/RankSortView.swift | 6 ++--- iAppStore/components/search/SearchHome.swift | 2 +- .../subscription/SubscriptionAddView.swift | 2 +- iAppStore/iAppStoreApp.swift | 2 +- 9 files changed, 40 insertions(+), 18 deletions(-) diff --git a/iAppStore.xcodeproj/project.pbxproj b/iAppStore.xcodeproj/project.pbxproj index cc7763f..5a589f5 100644 --- a/iAppStore.xcodeproj/project.pbxproj +++ b/iAppStore.xcodeproj/project.pbxproj @@ -644,8 +644,8 @@ CODE_SIGN_ENTITLEMENTS = iAppStore/iAppStore.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "-"; - CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2023.04.03; + CODE_SIGN_STYLE = Manual; + CURRENT_PROJECT_VERSION = 2023.04.25; DEVELOPMENT_ASSET_PATHS = "\"iAppStore/Preview Content\""; DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; @@ -664,11 +664,10 @@ "@executable_path/Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 1.3.0; + MARKETING_VERSION = 1.4.0; PRODUCT_BUNDLE_IDENTIFIER = com.37iOS.iAppStore; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; - "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = ""; SUPPORTS_MACCATALYST = YES; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; @@ -685,8 +684,8 @@ CODE_SIGN_ENTITLEMENTS = iAppStore/iAppStore.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "-"; - CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2023.04.03; + CODE_SIGN_STYLE = Manual; + CURRENT_PROJECT_VERSION = 2023.04.25; DEVELOPMENT_ASSET_PATHS = "\"iAppStore/Preview Content\""; DEVELOPMENT_TEAM = ""; ENABLE_PREVIEWS = YES; @@ -705,11 +704,10 @@ "@executable_path/Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 11.0; - MARKETING_VERSION = 1.3.0; + MARKETING_VERSION = 1.4.0; PRODUCT_BUNDLE_IDENTIFIER = com.37iOS.iAppStore; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; - "PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = ""; SUPPORTS_MACCATALYST = YES; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; diff --git a/iAppStore/Network/APIService.swift b/iAppStore/Network/APIService.swift index a324b82..7ae96f0 100644 --- a/iAppStore/Network/APIService.swift +++ b/iAppStore/Network/APIService.swift @@ -33,7 +33,8 @@ public struct APIService { newFreeApplications(cid: String, country: String, limit: Int), newPaidApplications(cid: String, country: String, limit: Int), searchApp(word: String, country: String, limit: Int), - lookupApp(appid: String, country: String) + lookupApp(appid: String, country: String), + lookupBundleId(appid: String, country: String) func url() -> String { let url = APIService.shared.baseURL @@ -61,6 +62,8 @@ public struct APIService { return url + "search?term=\(word)&country=\(country)&limit=\(limit)&entity=software" case .lookupApp(appid: let appid, country: let country): return url + "\(country)/lookup?id=\(appid)" + case .lookupBundleId(appid: let appid, country: let country): + return url + "\(country)/lookup?bundleId=\(appid)" } } } @@ -83,7 +86,6 @@ public struct APIService { debugPrint(components.url!) var request = URLRequest(url: components.url!, cachePolicy: .reloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 60.0) request.httpMethod = "POST" - request.setValue("iAppStore/1.0 Mobile/15E148 Safari/604.1", forHTTPHeaderField: "User-Agent") let task = URLSession.shared.dataTask(with: request) { (data, response, error) in guard let data = data else { DispatchQueue.main.async { diff --git a/iAppStore/Shared/UI/LoadingView.swift b/iAppStore/Shared/UI/LoadingView.swift index 6fb646e..2a3511f 100644 --- a/iAppStore/Shared/UI/LoadingView.swift +++ b/iAppStore/Shared/UI/LoadingView.swift @@ -41,7 +41,7 @@ struct LoadingView: View { var animateText: some View { HStack(spacing: 1) { - ForEach(loadingText.indices) { index in + ForEach(loadingText.indices, id: \.self) { index in Text(loadingText[index]) .font(.headline) .fontWeight(.heavy) diff --git a/iAppStore/ViewModels/AppDetailModel.swift b/iAppStore/ViewModels/AppDetailModel.swift index 86b08e7..5049d42 100644 --- a/iAppStore/ViewModels/AppDetailModel.swift +++ b/iAppStore/ViewModels/AppDetailModel.swift @@ -36,6 +36,28 @@ class AppDetailModel: ObservableObject { if appId != nil { self.app = response.results.first } + if let word = keyWord { + self.lookupBundleId(word: word, regionId: regionId) + } + case .failure(_): + break + } + } + } + + /// search bundleId + func lookupBundleId(word: String, regionId: String) { + guard let bundleId = word.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else { + return + } + + let endpoint = APIService.Endpoint.lookupBundleId(appid: bundleId, country: regionId) + APIService.shared.POST(endpoint: endpoint, params: nil) { (result: Result) in + switch result { + case let .success(response): + if let app = response.results.first { + self.results.insert(app, at: 0) + } case .failure(_): break } diff --git a/iAppStore/components/rankLists/AppDetailContentView.swift b/iAppStore/components/rankLists/AppDetailContentView.swift index e3fda84..48e3bd2 100644 --- a/iAppStore/components/rankLists/AppDetailContentView.swift +++ b/iAppStore/components/rankLists/AppDetailContentView.swift @@ -241,7 +241,7 @@ struct AppDetailScreenShotView: View { var body: some View { ScrollView(.horizontal, showsIndicators: false) { LazyHStack() { - ForEach(0..<(screenshotUrls ?? [String]()).count) { index in + ForEach(0..<(screenshotUrls ?? [String]()).count, id: \.self) { index in let url = screenshotUrls![index] Button(action: { selectedImgUrl = url.imageAppleScale() diff --git a/iAppStore/components/rankLists/RankSortView.swift b/iAppStore/components/rankLists/RankSortView.swift index fd2c451..52f2a23 100644 --- a/iAppStore/components/rankLists/RankSortView.swift +++ b/iAppStore/components/rankLists/RankSortView.swift @@ -70,7 +70,7 @@ extension RankSortView { var rankContent: some View { ScrollView { - ForEach(0..