-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix lookup API to return data based on the country #52
base: master
Are you sure you want to change the base?
Conversation
…to be able to use it in the construction of the URL.
@@ -88,30 +88,42 @@ extension PrinceOfVersions { | |||
|
|||
If parameter `notificationFrequency` is set to `.always` and latest version of the app is bigger than installed version, method will always return `.newUpdateAvailable`. However, if the`notificationFrequency` is set to `.once`, only first time this method is called for the same latest app version, it will return `.newUpdateAvailable`, each subsequent call, it will return `.noUpdateAvailable`. | |||
|
|||
If the optional `country` parameter is provided, the API request will target the specified App Store region (e.g., `"no"` for Norway). If `country` is not provided, the API will fallback to its default behavior, typically fetching data from the U.S. App Store. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put a little easter egg in here :) :)
Set country example to hr (Croatia) or mk (Macedonia), you pick :)
- Parameters: | ||
* bundle: Bundle where .plist file is stored in which app identifier and app versions should be checked. | ||
* trackPhaseRelease: Boolean that indicates whether PoV should notify about new version after 7 days when app is fully rolled out or immediately. Default value is `YES`. | ||
* callbackQueue: The queue on which the completion handler is dispatched. By default, `main` queue is used. | ||
* notificationFrequency: Determines update status appearance frequency. | ||
* country: Optional parameter to specify the App Store region to target (e.g., `"no"` for Norway). Defaults to `nil`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same in here
@@ -111,11 +111,14 @@ public extension PrinceOfVersions { | |||
|
|||
If parameter `notificationFrequency` is set to `.always` and latest version of the app is bigger than installed version, method will always return `.newUpdateAvailable`. However, if the`notificationFrequency` is set to `.once`, only first time this method is called for the same latest app version, it will return `.newUpdateAvailable`, each subsequent call, it will return `.noUpdateAvailable`. | |||
|
|||
If the optional `country` parameter is provided, the API request will target the specified App Store region (e.g., `"no"` for Norway). If `country` is not provided, the API will fallback to its default behavior, typically fetching data from the U.S. App Store. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Find all occurrences of "no"
(Norway) and change it with hr/mk :)
var urlString = "https://itunes.apple.com/lookup?bundleId=\(bundleIdentifier)" | ||
|
||
// Append the country parameter if provided | ||
if let country = country { | ||
urlString += "&country=\(country)" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use URL components for this, so do this instead:
guard
let bundleIdentifier = bundle.bundleIdentifier,
var url = URL(string: "https://itunes.apple.com/lookup")
else {
callbackQueue.async {
completion(Result.failure(PoVError.invalidJsonData))
}
return nil
}
let queryItems: [URLQueryItem] = [
URLQueryItem(name: "bundleId", value: bundleIdentifier),
URLQueryItem(name: "country", value: country)
].filter { $0.value != nil }
url.append(queryItems: queryItems)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the suggested change.
I just changed the url.append(queryItems: queryItems)
since it is supported from iOS 16.0+.
The App Store Lookup API defaults to the U.S. store (country=us) if no country parameter is specified. If your app isn't available in the U.S. store, this would result in an empty response.
By appending country in the URL, the API will query the country store, where your app is available, thus returning the expected data.