mirror of
https://github.com/majd/ipatool
synced 2026-11-28 10:17:52 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3a54098ea | ||
|
|
69c07d0062 | ||
|
|
f0922b303e | ||
|
|
5a4d2f5e8d | ||
|
|
972f0b2cd0 | ||
|
|
03993b2b93 | ||
|
|
5009048d44 | ||
|
|
59fb28cee0 | ||
|
|
5f1fb02a12 | ||
|
|
32c6012918 | ||
|
|
f55e9ac53b | ||
|
|
a83dcb2849 | ||
|
|
6ff82c66aa | ||
|
|
c4610ca808 | ||
|
|
1563a82a20 | ||
|
|
48ed1df5c7 | ||
|
|
1448ca3ebc | ||
|
|
a3e483830f | ||
|
|
8cfd902bbf | ||
|
|
8165331378 | ||
|
|
bed12a55a9 | ||
|
|
73a416c917 |
No files matched your search
@@ -59,6 +59,7 @@ DerivedData/
|
||||
*.ipa
|
||||
*.dSYM.zip
|
||||
*.dSYM
|
||||
.build*
|
||||
|
||||
## Playgrounds
|
||||
timeline.xctimeline
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
prefix ?= /usr/local
|
||||
bindir = $(prefix)/bin
|
||||
|
||||
build:
|
||||
xcodebuild -scheme ipatool -configuration release -archivePath .build archive
|
||||
|
||||
install: build
|
||||
install -d "$(bindir)"
|
||||
install ".build.xcarchive/Products/$(bindir)/ipatool" "$(bindir)"
|
||||
|
||||
uninstall:
|
||||
rm -rf "$(bindir)/ipatool"
|
||||
|
||||
clean:
|
||||
rm -rf .build.xcarchive
|
||||
|
||||
.PHONY: build install uninstall clean
|
||||
@@ -0,0 +1,95 @@
|
||||
# IPATool
|
||||
[](https://GitHub.com/majd/ipatool/releases/)
|
||||

|
||||

|
||||
[](https://github.com/majd/ipatool/blob/main/LICENSE)
|
||||
|
||||
`ipatool` is a command line tool that allows you to search for iOS apps on the [App Store](https://apps.apple.com) and download a copy of the app package, known as an _ipa_ file.
|
||||
|
||||

|
||||
|
||||
## Requirements
|
||||
* macOS 10.15 or later.
|
||||
* Apple ID set up to use the App Store.
|
||||
|
||||
## Installation
|
||||
|
||||
### Manual Install
|
||||
|
||||
You can grab the latest version of `ipatool` from [GitHub releases](https://github.com/majd/ipatool/releases).
|
||||
|
||||
### Homebrew
|
||||
|
||||
You can install `ipatool` using [Homebrew](https://brew.sh).
|
||||
|
||||
```
|
||||
$ brew tap majd/repo
|
||||
$ brew install ipatool
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
To search for apps on the App Store, use the `search` command.
|
||||
|
||||
```
|
||||
OVERVIEW: Search for iOS apps available on the App Store.
|
||||
|
||||
USAGE: ipatool search <term> [--limit <limit>] [--country <country>] [--device-family <device-family>] [--log-level <log-level>]
|
||||
|
||||
ARGUMENTS:
|
||||
<term> The term to search for.
|
||||
|
||||
OPTIONS:
|
||||
-l, --limit <limit> The maximum amount of search results to retrieve.
|
||||
(default: 5)
|
||||
-c, --country <country> The two-letter (ISO 3166-1 alpha-2) country code for
|
||||
the iTunes Store. (default: US)
|
||||
-d, --device-family <device-family>
|
||||
The device family to limit the search query to.
|
||||
(default: iPhone)
|
||||
--log-level <log-level> The log level. (default: info)
|
||||
--version Show the version.
|
||||
-h, --help Show help information.
|
||||
```
|
||||
|
||||
To download a copy of the ipa file, use the `download` command.
|
||||
|
||||
```
|
||||
OVERVIEW: Download (encrypted) iOS app packages from the App Store.
|
||||
|
||||
USAGE: ipatool download --bundle-identifier <bundle-identifier> [--email <email>] [--password <password>] [--auth-code <auth-code>] [--country <country>] [--device-family <device-family>] [--log-level <log-level>]
|
||||
|
||||
OPTIONS:
|
||||
-b, --bundle-identifier <bundle-identifier>
|
||||
The bundle identifier of the target iOS app.
|
||||
-e, --email <email> The email address for the Apple ID.
|
||||
-p, --password <password>
|
||||
The password for the Apple ID.
|
||||
--auth-code <auth-code> The 2FA code for the Apple ID.
|
||||
-c, --country <country> The two-letter (ISO 3166-1 alpha-2) country code for the iTunes Store. (default: US)
|
||||
-d, --device-family <device-family>
|
||||
The device family to limit the search query to. (default: iPhone)
|
||||
--log-level <log-level> The log level. (default: info)
|
||||
--version Show the version.
|
||||
-h, --help Show help information.
|
||||
```
|
||||
|
||||
**Note:** You can specify the Apple ID email address and username as arguments when using the tool or by setting them as environment variables (`IPATOOL_EMAIL` and `IPATOOL_PASSWORD`). If you do not specify this information using either of those methods, the tool will prompt for user input in an interactive session. Similarly, you can supply the 2FA code interactively or using the environment variable `IPATOOL_2FA_CODE`.
|
||||
|
||||
## Common Knowledge
|
||||
|
||||
**Are my Apple ID credentials stored safely?**
|
||||
|
||||
The tool does not store your credentials anywhere and it only communicates with Apple servers directly. Feel free to go through the source code.
|
||||
|
||||
**Will my Apple ID get flagged for using this tool?**
|
||||
|
||||
Maybe, but probably not. While this tool communicates with iTunes and the App Store directly, mimicking the behavior of iTunes running on macOS, I cannot guarantee its safety. I recommend using a throwaway Apple ID. **Use this tool at your own risk**.
|
||||
|
||||
**Can I use this tool to download paid apps without paying for them?**
|
||||
|
||||
**No**. This is is not a piracy tool; you can only download apps that you have previously installed on your iOS device. This limitation applies to free apps as well. Essentially, your account must already have a license for the app you are trying to download.
|
||||
|
||||
**Can I use this tool to sideload unsupported iOS apps on Apple Silicon Macs?**
|
||||
|
||||
While it was previously possible to download ipa files using this tool and install them on Macs running on Apple Silicon, this is no longer the case as of recently. Apple stopped serving macOS compatible `sinf` data for the app package. You could, however, use this tool to get a copy of the iOS app and use a jailbroken iOS device to strip any codesigning requirements then codesign the app again using an adhoc signature to run on Apple Silicon.
|
||||
+144
-57
@@ -16,37 +16,38 @@ struct Download: ParsableCommand {
|
||||
@Option(name: [.short, .long], help: "The bundle identifier of the target iOS app.")
|
||||
private var bundleIdentifier: String
|
||||
|
||||
@Option(name: [.short, .long], help: "The email address for the Apple ID.")
|
||||
private var email: String?
|
||||
@Option(name: [.short, .customLong("email")], help: "The email address for the Apple ID.")
|
||||
private var emailArgument: String?
|
||||
|
||||
@Option(name: [.short, .long], help: "The password for the Apple ID.")
|
||||
private var password: String?
|
||||
@Option(name: [.short, .customLong("password")], help: "The password for the Apple ID.")
|
||||
private var passwordArgument: String?
|
||||
|
||||
@Option
|
||||
@Option(name: [.customLong("auth-code")], help: "The 2FA code for the Apple ID.")
|
||||
private var authCodeArgument: String?
|
||||
|
||||
@Option(name: [.short, .long], help: "The two-letter (ISO 3166-1 alpha-2) country code for the iTunes Store.")
|
||||
private var country: String = "US"
|
||||
|
||||
@Option(name: [.short, .long], help: "The device family to limit the search query to.")
|
||||
private var deviceFamily: iTunesRequest.DeviceFamily = .phone
|
||||
|
||||
@Option(name: [.long], help: "The log level.")
|
||||
private var logLevel: LogLevel = .info
|
||||
|
||||
lazy var logger = ConsoleLogger(level: logLevel)
|
||||
}
|
||||
|
||||
extension Download {
|
||||
func run() throws {
|
||||
let logger = ConsoleLogger(level: logLevel)
|
||||
|
||||
mutating func app(with bundleIdentifier: String, country: String) -> iTunesResponse.Result {
|
||||
logger.log("Creating HTTP client...", level: .debug)
|
||||
let httpClient = HTTPClient(urlSession: URLSession.shared)
|
||||
|
||||
logger.log("Creating iTunes client...", level: .debug)
|
||||
let itunesClient = iTunesClient(httpClient: httpClient)
|
||||
|
||||
logger.log("Creating App Store client...", level: .debug)
|
||||
let storeClient = StoreClient(httpClient: httpClient)
|
||||
|
||||
logger.log("Creating download client...", level: .debug)
|
||||
let downloadClient = HTTPDownloadClient()
|
||||
|
||||
logger.log("Querying the iTunes store for '\(bundleIdentifier)'...", level: .info)
|
||||
let app: iTunesResponse.Result
|
||||
|
||||
do {
|
||||
app = try itunesClient.lookup(bundleIdentifier: bundleIdentifier)
|
||||
logger.log("Querying the iTunes Store for '\(bundleIdentifier)' in country '\(country)'...", level: .info)
|
||||
return try itunesClient.lookup(bundleIdentifier: bundleIdentifier, country: country, deviceFamily: deviceFamily)
|
||||
} catch {
|
||||
logger.log("\(error)", level: .debug)
|
||||
|
||||
@@ -59,45 +60,62 @@ extension Download {
|
||||
|
||||
_exit(1)
|
||||
}
|
||||
logger.log("Found app: \(app.name) (\(app.version)).", level: .debug)
|
||||
|
||||
let email: String
|
||||
let password: String
|
||||
|
||||
if let cliEmail = self.email {
|
||||
email = cliEmail
|
||||
} else if let envEmail = ProcessInfo.processInfo.environment["IPATOOL_EMAIL"] {
|
||||
email = envEmail
|
||||
} else if let inputEmail = String(validatingUTF8: UnsafePointer<CChar>(getpass(logger.compile("Enter Apple ID email: ", level: .warning)))) {
|
||||
email = inputEmail
|
||||
}
|
||||
|
||||
mutating func email() -> String {
|
||||
if let email = emailArgument {
|
||||
return email
|
||||
} else if let email = ProcessInfo.processInfo.environment["IPATOOL_EMAIL"] {
|
||||
return email
|
||||
} else if let email = String(validatingUTF8: UnsafePointer<CChar>(getpass(logger.compile("Enter Apple ID email: ", level: .warning)))) {
|
||||
return email
|
||||
} else {
|
||||
logger.log("An Apple ID email address is required.", level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
|
||||
if let cliPassword = self.password {
|
||||
password = cliPassword
|
||||
} else if let envPassword = ProcessInfo.processInfo.environment["IPATOOL_PASSWORD"] {
|
||||
password = envPassword
|
||||
} else if let inputPassword = String(validatingUTF8: UnsafePointer<CChar>(getpass(logger.compile("Enter Apple ID password: ", level: .warning)))) {
|
||||
password = inputPassword
|
||||
}
|
||||
|
||||
mutating func password() -> String {
|
||||
if let password = passwordArgument {
|
||||
return password
|
||||
} else if let password = ProcessInfo.processInfo.environment["IPATOOL_PASSWORD"] {
|
||||
return password
|
||||
} else if let password = String(validatingUTF8: UnsafePointer<CChar>(getpass(logger.compile("Enter Apple ID password: ", level: .warning)))) {
|
||||
return password
|
||||
} else {
|
||||
logger.log("An Apple ID password is required.", level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
let account: StoreResponse.Account
|
||||
mutating func authCode() -> String {
|
||||
if let authCode = authCodeArgument {
|
||||
return authCode
|
||||
} else if let authCode = ProcessInfo.processInfo.environment["IPATOOL_2FA_CODE"] {
|
||||
return authCode
|
||||
} else if let authCode = String(validatingUTF8: UnsafePointer<CChar>(getpass(logger.compile("Enter 2FA code: ", level: .warning)))) {
|
||||
return authCode
|
||||
} else {
|
||||
logger.log("A 2FA auth-code is required.", level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
mutating func authenticate(email: String, password: String) -> StoreResponse.Account {
|
||||
logger.log("Creating HTTP client...", level: .debug)
|
||||
let httpClient = HTTPClient(urlSession: URLSession.shared)
|
||||
|
||||
logger.log("Creating App Store client...", level: .debug)
|
||||
let storeClient = StoreClient(httpClient: httpClient)
|
||||
|
||||
do {
|
||||
logger.log("Authenticating with the App Store...", level: .info)
|
||||
account = try storeClient.authenticate(email: email, password: password)
|
||||
return try storeClient.authenticate(email: email, password: password)
|
||||
} catch {
|
||||
switch error {
|
||||
case StoreResponse.Error.codeRequired:
|
||||
let code = String(validatingUTF8: UnsafePointer<CChar>(getpass(logger.compile("Enter 2FA code: ", level: .warning))))
|
||||
|
||||
do {
|
||||
account = try storeClient.authenticate(email: email, password: password, code: code)
|
||||
return try storeClient.authenticate(email: email, password: password, code: authCode())
|
||||
} catch {
|
||||
logger.log("\(error)", level: .debug)
|
||||
|
||||
@@ -135,32 +153,101 @@ extension Download {
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mutating func item(from app: iTunesResponse.Result, account: StoreResponse.Account) -> StoreResponse.Item {
|
||||
logger.log("Creating HTTP client...", level: .debug)
|
||||
let httpClient = HTTPClient(urlSession: URLSession.shared)
|
||||
|
||||
logger.log("Creating App Store client...", level: .debug)
|
||||
let storeClient = StoreClient(httpClient: httpClient)
|
||||
|
||||
do {
|
||||
logger.log("Requesting a signed copy of '\(app.identifier)' from the App Store...", level: .info)
|
||||
return try storeClient.item(identifier: "\(app.identifier)", directoryServicesIdentifier: account.directoryServicesIdentifier)
|
||||
} catch {
|
||||
logger.log("\(error)", level: .debug)
|
||||
|
||||
switch error {
|
||||
case StoreClient.Error.invalidResponse:
|
||||
logger.log("Received invalid response.", level: .error)
|
||||
case StoreResponse.Error.invalidItem:
|
||||
logger.log("Received invalid store item.", level: .error)
|
||||
case StoreResponse.Error.invalidLicense:
|
||||
logger.log("Your Apple ID does not have a license for this app. Download the app on an iOS device to obtain a license.", level: .error)
|
||||
default:
|
||||
logger.log("An unknown error has occurred.", level: .error)
|
||||
}
|
||||
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
mutating func download(item: StoreResponse.Item, to targetURL: URL) {
|
||||
logger.log("Creating download client...", level: .debug)
|
||||
let downloadClient = HTTPDownloadClient()
|
||||
|
||||
do {
|
||||
logger.log("Downloading app package...", level: .info)
|
||||
try downloadClient.download(from: item.url, to: targetURL) { [logger] progress in
|
||||
logger.log("Downloading app package... [\(Int((progress * 100).rounded()))%]",
|
||||
prefix: "\u{1B}[1A\u{1B}[K",
|
||||
level: .info)
|
||||
}
|
||||
} catch {
|
||||
logger.log("\(error)", level: .debug)
|
||||
logger.log("An error has occurred while downloading the app package.", level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
mutating func applyPatches(item: StoreResponse.Item, email: String, path: String) {
|
||||
logger.log("Creating signature client...", level: .debug)
|
||||
let signatureClient = SignatureClient(fileManager: .default, filePath: path)
|
||||
|
||||
do {
|
||||
logger.log("Applying patches...", level: .info)
|
||||
try signatureClient.appendMetadata(item: item, email: email)
|
||||
try signatureClient.appendSignature(item: item)
|
||||
} catch {
|
||||
logger.log("\(error)", level: .debug)
|
||||
logger.log("Failed to apply patches. The ipa file will be left incomplete.", level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
mutating func run() throws {
|
||||
// Query for app
|
||||
let app: iTunesResponse.Result = app(with: bundleIdentifier, country: country)
|
||||
logger.log("Found app: \(app.name) (\(app.version)).", level: .debug)
|
||||
|
||||
// Get Apple ID email
|
||||
let email: String = email()
|
||||
|
||||
// Get Apple ID password
|
||||
let password: String = password()
|
||||
|
||||
// Authenticate with the App Store
|
||||
let account: StoreResponse.Account = authenticate(email: email, password: password)
|
||||
logger.log("Authenticated as '\(account.firstName) \(account.lastName)'.", level: .info)
|
||||
|
||||
logger.log("Requesting a signed copy of '\(app.identifier)' from the App Store...", level: .info)
|
||||
let item = try storeClient.item(identifier: "\(app.identifier)", directoryServicesIdentifier: account.directoryServicesIdentifier)
|
||||
// Query for store item
|
||||
let item: StoreResponse.Item = item(from: app, account: account)
|
||||
logger.log("Received a response of the signed copy: \(item.md5).", level: .debug)
|
||||
|
||||
logger.log("Creating signature client...", level: .debug)
|
||||
|
||||
// Generate file name
|
||||
let path = FileManager.default.currentDirectoryPath
|
||||
.appending("/\(bundleIdentifier)_\(app.identifier)_v\(app.version)_\(Int.random(in: 100...999))")
|
||||
.appending(".ipa")
|
||||
|
||||
logger.log("Output path: \(path).", level: .debug)
|
||||
let signatureClient = SignatureClient(fileManager: .default, filePath: path)
|
||||
|
||||
logger.log("Downloading app package...", level: .info)
|
||||
try downloadClient.download(from: item.url, to: URL(fileURLWithPath: path)) { progress in
|
||||
logger.log("Downloading app package... [\(Int((progress * 100).rounded()))%]",
|
||||
prefix: "\u{1B}[1A\u{1B}[K",
|
||||
level: .info)
|
||||
}
|
||||
// Download app package
|
||||
download(item: item, to: URL(fileURLWithPath: path))
|
||||
logger.log("Saved app package to \(URL(fileURLWithPath: path).lastPathComponent).", level: .info)
|
||||
|
||||
logger.log("Applying patches...", level: .info)
|
||||
try signatureClient.appendMetadata(item: item, email: email)
|
||||
try signatureClient.appendSignature(item: item)
|
||||
|
||||
// Apply patches
|
||||
applyPatches(item: item, email: email, path: path)
|
||||
logger.log("Done.", level: .info)
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ struct IPATool: ParsableCommand {
|
||||
static var configuration: CommandConfiguration {
|
||||
return .init(commandName: "ipatool",
|
||||
abstract: "A cli tool for interacting with Apple's ipa files.",
|
||||
version: "1.0.0",
|
||||
version: "1.0.7",
|
||||
subcommands: [Download.self, Search.self])
|
||||
}
|
||||
}
|
||||
@@ -13,20 +13,26 @@ struct Search: ParsableCommand {
|
||||
return .init(abstract: "Search for iOS apps available on the App Store.")
|
||||
}
|
||||
|
||||
@Option
|
||||
private var logLevel: LogLevel = .info
|
||||
@Argument(help: "The term to search for.")
|
||||
private var term: String
|
||||
|
||||
@Option
|
||||
@Option(name: [.short, .long], help: "The maximum amount of search results to retrieve.")
|
||||
private var limit: Int = 5
|
||||
|
||||
@Argument(help: "The term to search for.")
|
||||
var term: String
|
||||
@Option(name: [.short, .long], help: "The two-letter (ISO 3166-1 alpha-2) country code for the iTunes Store.")
|
||||
private var country: String = "US"
|
||||
|
||||
@Option(name: [.short, .long], help: "The device family to limit the search query to.")
|
||||
private var deviceFamily: iTunesRequest.DeviceFamily = .phone
|
||||
|
||||
@Option(name: [.long], help: "The log level.")
|
||||
private var logLevel: LogLevel = .info
|
||||
|
||||
lazy var logger = ConsoleLogger(level: logLevel)
|
||||
}
|
||||
|
||||
extension Search {
|
||||
func run() throws {
|
||||
let logger = ConsoleLogger(level: logLevel)
|
||||
|
||||
mutating func results(with term: String, country: String) -> [iTunesResponse.Result] {
|
||||
logger.log("Creating HTTP client...", level: .debug)
|
||||
let httpClient = HTTPClient(urlSession: URLSession.shared)
|
||||
|
||||
@@ -34,19 +40,32 @@ extension Search {
|
||||
let itunesClient = iTunesClient(httpClient: httpClient)
|
||||
|
||||
do {
|
||||
logger.log("Searching for '\(term)'...", level: .info)
|
||||
let results = try itunesClient.search(term: term, limit: limit)
|
||||
logger.log("Searching for '\(term)' using the '\(country)' store front...", level: .info)
|
||||
let results = try itunesClient.search(term: term, limit: limit, country: country, deviceFamily: deviceFamily)
|
||||
|
||||
guard !results.isEmpty else {
|
||||
logger.log("No results found.", level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
|
||||
logger.log("Found \(results.count) results:\n\(results.enumerated().map({ "\($0 + 1). \($1.name): \($1.bundleIdentifier) (\($1.version))." }).joined(separator: "\n"))", level: .info)
|
||||
|
||||
return results
|
||||
} catch {
|
||||
logger.log("\(error)", level: .debug)
|
||||
logger.log("An unknown error has occurred.", level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
mutating func run() throws {
|
||||
// Search the iTunes store
|
||||
let results = results(with: term, country: country)
|
||||
|
||||
// Compile output
|
||||
let output = results
|
||||
.enumerated()
|
||||
.map({ "\($0 + 1). \($1.name): \($1.bundleIdentifier) (\($1.version))." })
|
||||
.joined(separator: "\n")
|
||||
|
||||
logger.log("Found \(results.count) \(results.count == 1 ? "result" : "results"):\n\(output)", level: .info)
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ extension StoreRequest: HTTPRequest {
|
||||
|
||||
var headers: [String: String] {
|
||||
var headers: [String: String] = [
|
||||
"User-Agent": "Configurator/2.0 (Macintosh; OS X 10.12.6; 16G29) AppleWebKit/2603.3.8",
|
||||
"User-Agent": "Configurator/2.15 (Macintosh; OS X 11.0.0; 16G29) AppleWebKit/2603.3.8",
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
]
|
||||
|
||||
|
||||
@@ -8,16 +8,23 @@
|
||||
import Foundation
|
||||
|
||||
protocol iTunesClientInterface {
|
||||
func lookup(bundleIdentifier: String, completion: @escaping (Result<iTunesResponse.Result, Error>) -> Void)
|
||||
func search(term: String, limit: Int, completion: @escaping (Result<[iTunesResponse.Result], Error>) -> Void)
|
||||
func lookup(bundleIdentifier: String,
|
||||
country: String,
|
||||
deviceFamily: iTunesRequest.DeviceFamily,
|
||||
completion: @escaping (Result<iTunesResponse.Result, Error>) -> Void)
|
||||
func search(term: String,
|
||||
limit: Int,
|
||||
country: String,
|
||||
deviceFamily: iTunesRequest.DeviceFamily,
|
||||
completion: @escaping (Result<[iTunesResponse.Result], Error>) -> Void)
|
||||
}
|
||||
|
||||
extension iTunesClientInterface {
|
||||
func lookup(bundleIdentifier: String) throws -> iTunesResponse.Result {
|
||||
func lookup(bundleIdentifier: String, country: String, deviceFamily: iTunesRequest.DeviceFamily) throws -> iTunesResponse.Result {
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
var result: Result<iTunesResponse.Result, Error>?
|
||||
|
||||
lookup(bundleIdentifier: bundleIdentifier) {
|
||||
lookup(bundleIdentifier: bundleIdentifier, country: country, deviceFamily: deviceFamily) {
|
||||
result = $0
|
||||
semaphore.signal()
|
||||
}
|
||||
@@ -34,11 +41,11 @@ extension iTunesClientInterface {
|
||||
}
|
||||
}
|
||||
|
||||
func search(term: String, limit: Int) throws -> [iTunesResponse.Result] {
|
||||
func search(term: String, limit: Int, country: String, deviceFamily: iTunesRequest.DeviceFamily) throws -> [iTunesResponse.Result] {
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
var result: Result<[iTunesResponse.Result], Error>?
|
||||
|
||||
search(term: term, limit: limit) {
|
||||
search(term: term, limit: limit, country: country, deviceFamily: deviceFamily) {
|
||||
result = $0
|
||||
semaphore.signal()
|
||||
}
|
||||
@@ -63,8 +70,11 @@ final class iTunesClient: iTunesClientInterface {
|
||||
self.httpClient = httpClient
|
||||
}
|
||||
|
||||
func lookup(bundleIdentifier: String, completion: @escaping (Result<iTunesResponse.Result, Swift.Error>) -> Void) {
|
||||
let request = iTunesRequest.lookup(bundleIdentifier: bundleIdentifier)
|
||||
func lookup(bundleIdentifier: String,
|
||||
country: String,
|
||||
deviceFamily: iTunesRequest.DeviceFamily,
|
||||
completion: @escaping (Result<iTunesResponse.Result, Swift.Error>) -> Void) {
|
||||
let request = iTunesRequest.lookup(bundleIdentifier: bundleIdentifier, country: country, deviceFamily: deviceFamily)
|
||||
|
||||
httpClient.send(request) { result in
|
||||
switch result {
|
||||
@@ -82,8 +92,12 @@ final class iTunesClient: iTunesClientInterface {
|
||||
}
|
||||
}
|
||||
|
||||
func search(term: String, limit: Int, completion: @escaping (Result<[iTunesResponse.Result], Swift.Error>) -> Void) {
|
||||
let request = iTunesRequest.search(term: term, limit: limit)
|
||||
func search(term: String,
|
||||
limit: Int,
|
||||
country: String,
|
||||
deviceFamily: iTunesRequest.DeviceFamily,
|
||||
completion: @escaping (Result<[iTunesResponse.Result], Swift.Error>) -> Void) {
|
||||
let request = iTunesRequest.search(term: term, limit: limit, country: country, deviceFamily: deviceFamily)
|
||||
|
||||
httpClient.send(request) { result in
|
||||
switch result {
|
||||
|
||||
@@ -5,11 +5,31 @@
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import ArgumentParser
|
||||
|
||||
enum iTunesRequest {
|
||||
case search(term: String, limit: Int)
|
||||
case lookup(bundleIdentifier: String)
|
||||
case search(term: String, limit: Int, country: String, deviceFamily: DeviceFamily = .phone)
|
||||
case lookup(bundleIdentifier: String, country: String, deviceFamily: DeviceFamily = .phone)
|
||||
}
|
||||
|
||||
extension iTunesRequest {
|
||||
enum DeviceFamily: String, ExpressibleByArgument {
|
||||
case phone = "iPhone"
|
||||
case pad = "iPad"
|
||||
|
||||
var defaultValueDescription: String {
|
||||
return rawValue
|
||||
}
|
||||
|
||||
var entity: String {
|
||||
switch self {
|
||||
case .phone:
|
||||
return "software"
|
||||
case .pad:
|
||||
return "iPadSoftware"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension iTunesRequest: HTTPRequest {
|
||||
@@ -28,10 +48,10 @@ extension iTunesRequest: HTTPRequest {
|
||||
|
||||
var payload: HTTPPayload? {
|
||||
switch self {
|
||||
case let .lookup(bundleIdentifier):
|
||||
return .urlEncoding(["media": "software", "bundleId": bundleIdentifier, "limit": "1"])
|
||||
case let .search(term, limit):
|
||||
return .urlEncoding(["media": "software", "term": term, "limit": "\(limit)"])
|
||||
case let .lookup(bundleIdentifier, country, deviceFamily):
|
||||
return .urlEncoding(["media": "software", "bundleId": bundleIdentifier, "limit": "1", "country": country, "entity": deviceFamily.entity])
|
||||
case let .search(term, limit, country, deviceFamily):
|
||||
return .urlEncoding(["media": "software", "term": term, "limit": "\(limit)", "country": country, "entity": deviceFamily.entity])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,7 +113,6 @@
|
||||
A9CA48D02659138600BC09D5 /* Networking */,
|
||||
A9CA48F6265942A600BC09D5 /* Signature */,
|
||||
A9CA48EA265929E000BC09D5 /* Store */,
|
||||
A9CA48CE2658FC7400BC09D5 /* IPATool.swift */,
|
||||
A9CA48C12658F93F00BC09D5 /* main.swift */,
|
||||
);
|
||||
path = Source;
|
||||
@@ -123,6 +122,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A9CA48CC2658FBF700BC09D5 /* Download.swift */,
|
||||
A9CA48CE2658FC7400BC09D5 /* IPATool.swift */,
|
||||
A9CA49022659627A00BC09D5 /* Search.swift */,
|
||||
);
|
||||
path = Commands;
|
||||
@@ -397,7 +397,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.15;
|
||||
PRODUCT_NAME = ipatool;
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
@@ -407,7 +407,7 @@
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.15;
|
||||
PRODUCT_NAME = ipatool;
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "A9CA48BD2658F93F00BC09D5"
|
||||
BuildableName = "IPATool"
|
||||
BuildableName = "ipatool"
|
||||
BlueprintName = "IPATool"
|
||||
ReferencedContainer = "container:ipatool.xcodeproj">
|
||||
</BuildableReference>
|
||||
@@ -45,11 +45,37 @@
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "A9CA48BD2658F93F00BC09D5"
|
||||
BuildableName = "IPATool"
|
||||
BuildableName = "ipatool"
|
||||
BlueprintName = "IPATool"
|
||||
ReferencedContainer = "container:ipatool.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
<CommandLineArguments>
|
||||
<CommandLineArgument
|
||||
argument = "download --help"
|
||||
isEnabled = "NO">
|
||||
</CommandLineArgument>
|
||||
<CommandLineArgument
|
||||
argument = "search "Swift Playgrounds" --device-family iPhone"
|
||||
isEnabled = "NO">
|
||||
</CommandLineArgument>
|
||||
<CommandLineArgument
|
||||
argument = "search "Swift Playgrounds" --device-family iPad"
|
||||
isEnabled = "YES">
|
||||
</CommandLineArgument>
|
||||
<CommandLineArgument
|
||||
argument = "download -b com.apple.TestFlight"
|
||||
isEnabled = "NO">
|
||||
</CommandLineArgument>
|
||||
<CommandLineArgument
|
||||
argument = "search --help"
|
||||
isEnabled = "NO">
|
||||
</CommandLineArgument>
|
||||
<CommandLineArgument
|
||||
argument = "search TestFlight --limit 5"
|
||||
isEnabled = "NO">
|
||||
</CommandLineArgument>
|
||||
</CommandLineArguments>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
@@ -62,7 +88,7 @@
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "A9CA48BD2658F93F00BC09D5"
|
||||
BuildableName = "IPATool"
|
||||
BuildableName = "ipatool"
|
||||
BlueprintName = "IPATool"
|
||||
ReferencedContainer = "container:ipatool.xcodeproj">
|
||||
</BuildableReference>
|
||||
|
||||
Reference in new issue
Block a user