Slide 1

Slide 1 text

Shipping your apps should be Fast and Easy

Slide 2

Slide 2 text

Indie developer (and part-time freelancer) based in Barcelona Pol Hi! I’m Pol

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

polpiella.dev

Slide 5

Slide 5 text

ioscinewsletter.com

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Shipping your apps should be Fast and Easy

Slide 8

Slide 8 text

Shipping your apps can be Slow and Hard

Slide 9

Slide 9 text

Translations Traducciones ت ر ج م ا ت Переклади Çeviriler Übersetzungen Traduzioni Traduccions Oversettelser Übersetzungen Tłumaczenia Μεταφράσεις Vertalingen Traduçoes Bản dịch การแปล 翻译

Slide 10

Slide 10 text

Translations Traducciones ت ر ج م ا ت Переклади Çeviriler Übersetzungen Traduzioni Traduccions Oversettelser Übersetzungen Tłumaczenia Μεταφράσεις Vertalingen Traduçoes Bản dịch การแปล 翻译 40 Locales

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Did you just submit a new update to the App Store? Don ’ t forget to add the Promotional Text 😊

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

App Store Connect API An overview of the App Store Connect API

Slide 19

Slide 19 text

IAP TestFlight Xcode Cloud Users & Roles Provisioning Customer Reviews Performance Reporting App Metadata App Clips

Slide 20

Slide 20 text

App Store Connect API? Who uses the App Store Connect API?

Slide 21

Slide 21 text

Using the App Store Connect API App Store Connect API A s t e p b y s te p gui de A s t e p b y s te p gui de

Slide 22

Slide 22 text

#1 Create a key #1 Create a key

Slide 23

Slide 23 text

#1 Create a key #1 Create a key

Slide 24

Slide 24 text

#1 Create a key #1 Create a key

Slide 25

Slide 25 text

#2 Create a JWT Token #2 Create a JWT Token

Slide 26

Slide 26 text

import SwiftJWT import Foundation struct JWTClaims: Claims { let iss: String let iat: Date? let exp: Date? let aud: String } final class TokenProvider { private let keyId: String private let issuerId: String private let privateKey: String private let now: () -> Date init(keyId: String, issuerId: String, privateKey: String, now: @escaping () -> Date = Date.init) { self.keyId = keyId self.issuerId = issuerId self.privateKey = privateKey self.now = now } func generateToken() throws - > String { let header = Header(typ: "JWT", kid: keyId) let claims = JWTClaims( iss: issuerId, iat: now(), exp: now() + 60 * 60 * 12, aud: "appstoreconnect-v1" ) var jwt = JWT(header: header, claims: claims) let keyData = Data(base64Encoded: privateKey) return try jwt.sign(using: .es256(privateKey: privateKey.data(using: .utf8)!)) } }

Slide 27

Slide 27 text

import SwiftJWT import Foundation struct JWTClaims: Claims { let iss: String let iat: Date? let exp: Date? let aud: String } final class TokenProvider { private let keyId: String private let issuerId: String private let privateKey: String private let now: () -> Date init(keyId: String, issuerId: String, privateKey: String, now: @escaping () -> Date = Date.init) { self.keyId = keyId self.issuerId = issuerId self.privateKey = privateKey self.now = now } func generateToken() throws - > String { let header = Header(typ: "JWT", kid: keyId) let claims = JWTClaims( iss: issuerId, iat: now(), exp: now() + 60 * 60 * 12, aud: "appstoreconnect-v1" ) var jwt = JWT(header: header, claims: claims) let keyData = Data(base64Encoded: privateKey) return try jwt.sign(using: .es256(privateKey: privateKey.data(using: .utf8)!)) } }

Slide 28

Slide 28 text

import SwiftJWT import Foundation struct JWTClaims: Claims { let iss: String let iat: Date? let exp: Date? let aud: String } final class TokenProvider { private let keyId: String private let issuerId: String private let privateKey: String private let now: () -> Date init(keyId: String, issuerId: String, privateKey: String, now: @escaping () -> Date = Date.init) { self.keyId = keyId self.issuerId = issuerId self.privateKey = privateKey self.now = now } func generateToken() throws - > String { let header = Header(typ: "JWT", kid: keyId) let claims = JWTClaims( iss: issuerId, iat: now(), exp: now() + 60 * 60 * 12, aud: "appstoreconnect-v1" ) var jwt = JWT(header: header, claims: claims) let keyData = Data(base64Encoded: privateKey) return try jwt.sign(using: .es256(privateKey: privateKey.data(using: .utf8)!)) } }

Slide 29

Slide 29 text

#3 Make a request #3 Make a request final class AppStoreConnectClient { private let session: URLSession private let tokenProvider: () - > String private let jsonDecoder: JSONDecoder private let baseURL = URL(string: "https: // api.appstoreconnect.apple.com/v1")! init(session: URLSession = .shared, tokenProvider: @escaping () - > String, jsonDecoder: JSONDecoder = .init()) { self.session = session self.tokenProvider = tokenProvider self.jsonDecoder = jsonDecoder } func fetchApps() async throws - > [App] { let url = baseURL.appendingPathComponent("apps") var request = URLRequest(url: url) request.httpMethod = "GET" request.setValue("Bearer \(tokenProvider())", forHTTPHeaderField: "Authorization") let (data, _) = try await session.data(for: request) let response = try jsonDecoder.decode(AppsResponse.self, from: data) return response.data } }

Slide 30

Slide 30 text

Tha t w i l l s a ve y ou a b u n ch o f t i m e a n d e ffo r t! Tha t w i l l s a ve y ou a b u n ch o f t i m e a n d e ffo r t! PRO TIPS PRO TIPS

Slide 31

Slide 31 text

Leverage OpenAPI specs Leverage OpenAPI specs

Slide 32

Slide 32 text

{ "openapi" : "3.0.1", "info" : { "title" : "App Store Connect API", "version" : "3.5", "x-platform" : "app_store_connect_api" }, "servers" : [ { "url" : "https: // api.appstoreconnect.apple.com/" } ], "paths" : { "/v1/actors" : { "get" : { "tags" : [ "Actors" ], "operationId" : "actors-get_collection", "parameters" : [ { "name" : "filter[id]", "in" : "query", "description" : "filter by id(s)", "schema" : { "type" : "array", "items" : { "type" : "string" } },

Slide 33

Slide 33 text

https://www.runway.team/blog/how-to-build-an-app-store-connect-api-client-in-swi ft -using-openapi

Slide 34

Slide 34 text

Don’t do it yourself! Don’t do it yourself!

Slide 35

Slide 35 text

final class AppStoreConnectClient { private let session: URLSession private let tokenProvider: () - > String private let jsonDecoder: JSONDecoder private let baseURL = URL(string: "https: // api.appstoreconnect.apple.com/v1")! init(session: URLSession = .shared, tokenProvider: @escaping () - > String, jsonDecoder: JSONDecoder = .init()) { self.session = session self.tokenProvider = tokenProvider self.jsonDecoder = jsonDecoder } func fetchApps() async throws - > [App] { let url = baseURL.appendingPathComponent("apps") var request = URLRequest(url: url) request.httpMethod = "GET" request.setValue("Bearer \(tokenProvider())", forHTTPHeaderField: "Authorization") let (data, _) = try await session.data(for: request) let response = try jsonDecoder.decode(AppsResponse.self, from: data) return response.data } }

Slide 36

Slide 36 text

import AppStoreConnect_Swift_SDK final class AppStoreConnectClient { private let provider: APIProvider init(provider: APIProvider) { self.provider = provider } func fetchApps() async throws - > [App] { try await provider .request(APIEndpoint.v1.apps.get()) .data } } Net wor k i ng c l i e n t tha t h a n d l es a ut h en t ic a tio n

Slide 37

Slide 37 text

import AppStoreConnect_Swift_SDK final class AppStoreConnectClient { private let provider: APIProvider init(provider: APIProvider) { self.provider = provider } func fetchApps() async throws - > [App] { try await provider .request(APIEndpoint.v1.apps.get()) .data } } Ty p e-sa fe e n d p o in t s , bu il t -in deco di n g

Slide 38

Slide 38 text

import AppStoreConnect_Swift_SDK final class AppStoreConnectClient { private let provider: APIProvider init(provider: APIProvider) { self.provider = provider } func fetchApps() async throws - > [App] { try await provider .request(APIEndpoint.v1.apps.get()) .data } } Aut o -ge nera te d C o da b l e m o d el s fo r re s p o n se s

Slide 39

Slide 39 text

Request what you need! Request what you need! import AppStoreConnect_Swift_SDK final class AppStoreConnectClient { private let provider: APIProvider init(provider: APIProvider) { self.provider = provider } func fetchApps() async throws - > [App] { try await provider .request(APIEndpoint.v1.apps.get()) .data } } import AppStoreConnect_Swift_SDK final class AppStoreConnectClient { private let provider: APIProvider init(provider: APIProvider) { self.provider = provider } func fetchApps() async throws - > [App] { let endpoint = APIEndpoint.v1.apps .get( parameters: .init( fieldsApps: [.name, .bundleID], limit: 10 ) ) return try await provider.request(endpoint).data } }

Slide 40

Slide 40 text

Automate your processes An d t ha n k m e l a t er! An d t ha n k m e l a t er! Automate your processes

Slide 41

Slide 41 text

Applying content from older versions Applying content from older versions

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

Did you just submit a new update to the App Store? Don ’ t forget to add the Promotional Text 😊

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

func createVersion(forApp app: String, withPlatform platform: Platform, andVersion version: String) async throws - > String { let appData = AppStoreVersionCreateRequest.Data.Relationships.App.Data( type: .apps, id: app ) let app = AppStoreVersionCreateRequest.Data.Relationships.App(data: appData) let relationships = AppStoreVersionCreateRequest.Data.Relationships(app: .init(data: appData)) let attributes = AppStoreVersionCreateRequest.Data.Attributes(platform: platform, versionString: version) let data = AppStoreVersionCreateRequest.Data( type: .appStoreVersions, attributes: attributes, relationships: relationships ) let versionRequest = APIEndpoint .v1 .appStoreVersions .post(.init(data: data)) let response = try await provider.request(versionRequest).data return response.id }

Slide 46

Slide 46 text

func createVersion(forApp app: String, withPlatform platform: Platform, andVersion version: String) async throws - > String { let appData = AppStoreVersionCreateRequest.Data.Relationships.App.Data( type: .apps, id: app ) let app = AppStoreVersionCreateRequest.Data.Relationships.App(data: appData) let relationships = AppStoreVersionCreateRequest.Data.Relationships(app: .init(data: appData)) let attributes = AppStoreVersionCreateRequest.Data.Attributes(platform: platform, versionString: version) let data = AppStoreVersionCreateRequest.Data( type: .appStoreVersions, attributes: attributes, relationships: relationships ) let versionRequest = APIEndpoint .v1 .appStoreVersions .post(.init(data: data)) let response = try await provider.request(versionRequest).data return response.id }

Slide 47

Slide 47 text

func createVersion(forApp app: String, withPlatform platform: Platform, andVersion version: String) async throws - > String { let appData = AppStoreVersionCreateRequest.Data.Relationships.App.Data( type: .apps, id: app ) let app = AppStoreVersionCreateRequest.Data.Relationships.App(data: appData) let relationships = AppStoreVersionCreateRequest.Data.Relationships(app: .init(data: appData)) let attributes = AppStoreVersionCreateRequest.Data.Attributes(platform: platform, versionString: version) let data = AppStoreVersionCreateRequest.Data( type: .appStoreVersions, attributes: attributes, relationships: relationships ) let versionRequest = APIEndpoint .v1 .appStoreVersions .post(.init(data: data)) let response = try await provider.request(versionRequest).data return response.id }

Slide 48

Slide 48 text

func getLatestLiveVersionPromotionalText(forApp app: String, withPlatform platform: Platform) async throws -> [AppStoreLanguage: String] { let platform: APIEndpoint.V1.Apps.WithID.AppStoreVersions.GetParameters.FilterPlatform = { switch platform { case .ios: return .ios case .macOs: return .macOs case .tvOs: return .tvOs case .visionOs: return .visionOs } }() let endpoint = APIEndpoint.v1.apps.id(app).appStoreVersions .get( parameters: .init( filterAppVersionState: [.processingForDistribution, .readyForDistribution, .pendingAppleRelease], filterPlatform: [platform], fieldsAppStoreVersionLocalizations: [.promotionalText, .locale], limit: 1, include: [.appStoreVersionLocalizations] ) ) let response = try await provider.request(endpoint) let localizations = response.included ?. compactMap { item in if case .appStoreVersionLocalization(let localization) = item { return localization } return nil } let easyAccessLocalizations: [String: AppStoreVersionLocalization] = localizations? .reduce(into: [String: AppStoreVersionLocalization](), { $0[$1.id] = $1 }) ?? [:] let latestVersionLocalizations = response.data.first ? . relationships ?. appStoreVersionLocalizations ? . data? .reduce(into: [AppStoreLanguage: String]()) { partialResult, localization in if let matchedLocalization = easyAccessLocalizations[localization.id], let promotionalText = matchedLocalization.attributes ?. promotionalText, let language = AppStoreLanguage(rawValue: matchedLocalization.attributes ?. locale ? ? "") { partialResult[language] = promotionalText } } return latestVersionLocalizations ?? [:] }

Slide 49

Slide 49 text

func getLatestLiveVersionPromotionalText(forApp app: String, withPlatform platform: Platform) async throws -> [AppStoreLanguage: String] { let platform: APIEndpoint.V1.Apps.WithID.AppStoreVersions.GetParameters.FilterPlatform = { switch platform { case .ios: return .ios case .macOs: return .macOs case .tvOs: return .tvOs case .visionOs: return .visionOs } }() let endpoint = APIEndpoint.v1.apps.id(app).appStoreVersions .get( parameters: .init( filterAppVersionState: [.processingForDistribution, .readyForDistribution, .pendingAppleRelease], filterPlatform: [platform], fieldsAppStoreVersionLocalizations: [.promotionalText, .locale], limit: 1, include: [.appStoreVersionLocalizations] ) ) let response = try await provider.request(endpoint) let localizations = response.included ?. compactMap { item in if case .appStoreVersionLocalization(let localization) = item { return localization } return nil } let easyAccessLocalizations: [String: AppStoreVersionLocalization] = localizations? .reduce(into: [String: AppStoreVersionLocalization](), { $0[$1.id] = $1 }) ?? [:] let latestVersionLocalizations = response.data.first ? . relationships ?. appStoreVersionLocalizations ? . data? .reduce(into: [AppStoreLanguage: String]()) { partialResult, localization in if let matchedLocalization = easyAccessLocalizations[localization.id], let promotionalText = matchedLocalization.attributes ?. promotionalText, let language = AppStoreLanguage(rawValue: matchedLocalization.attributes ?. locale ? ? "") { partialResult[language] = promotionalText } } return latestVersionLocalizations ?? [:] }

Slide 50

Slide 50 text

func getLatestLiveVersionPromotionalText(forApp app: String, withPlatform platform: Platform) async throws -> [AppStoreLanguage: String] { let platform: APIEndpoint.V1.Apps.WithID.AppStoreVersions.GetParameters.FilterPlatform = { switch platform { case .ios: return .ios case .macOs: return .macOs case .tvOs: return .tvOs case .visionOs: return .visionOs } }() let endpoint = APIEndpoint.v1.apps.id(app).appStoreVersions .get( parameters: .init( filterAppVersionState: [.processingForDistribution, .readyForDistribution, .pendingAppleRelease], filterPlatform: [platform], fieldsAppStoreVersionLocalizations: [.promotionalText, .locale], limit: 1, include: [.appStoreVersionLocalizations] ) ) let response = try await provider.request(endpoint) let localizations = response.included ?. compactMap { item in if case .appStoreVersionLocalization(let localization) = item { return localization } return nil } let easyAccessLocalizations: [String: AppStoreVersionLocalization] = localizations? .reduce(into: [String: AppStoreVersionLocalization](), { $0[$1.id] = $1 }) ?? [:] let latestVersionLocalizations = response.data.first ? . relationships ?. appStoreVersionLocalizations ? . data? .reduce(into: [AppStoreLanguage: String]()) { partialResult, localization in if let matchedLocalization = easyAccessLocalizations[localization.id], let promotionalText = matchedLocalization.attributes ?. promotionalText, let language = AppStoreLanguage(rawValue: matchedLocalization.attributes ?. locale ? ? "") { partialResult[language] = promotionalText } } return latestVersionLocalizations ?? [:] }

Slide 51

Slide 51 text

func getLatestLiveVersionPromotionalText(forApp app: String, withPlatform platform: Platform) async throws -> [AppStoreLanguage: String] { let platform: APIEndpoint.V1.Apps.WithID.AppStoreVersions.GetParameters.FilterPlatform = { switch platform { case .ios: return .ios case .macOs: return .macOs case .tvOs: return .tvOs case .visionOs: return .visionOs } }() let endpoint = APIEndpoint.v1.apps.id(app).appStoreVersions .get( parameters: .init( filterAppVersionState: [.processingForDistribution, .readyForDistribution, .pendingAppleRelease], filterPlatform: [platform], fieldsAppStoreVersionLocalizations: [.promotionalText, .locale], limit: 1, include: [.appStoreVersionLocalizations] ) ) let response = try await provider.request(endpoint) let localizations = response.included ?. compactMap { item in if case .appStoreVersionLocalization(let localization) = item { return localization } return nil } let easyAccessLocalizations: [String: AppStoreVersionLocalization] = localizations? .reduce(into: [String: AppStoreVersionLocalization](), { $0[$1.id] = $1 }) ?? [:] let latestVersionLocalizations = response.data.first ? . relationships ?. appStoreVersionLocalizations ? . data? .reduce(into: [AppStoreLanguage: String]()) { partialResult, localization in if let matchedLocalization = easyAccessLocalizations[localization.id], let promotionalText = matchedLocalization.attributes ?. promotionalText, let language = AppStoreLanguage(rawValue: matchedLocalization.attributes ?. locale ? ? "") { partialResult[language] = promotionalText } } return latestVersionLocalizations ?? [:] }

Slide 52

Slide 52 text

func getLatestLiveVersionPromotionalText(forApp app: String, withPlatform platform: Platform) async throws -> [AppStoreLanguage: String] { let platform: APIEndpoint.V1.Apps.WithID.AppStoreVersions.GetParameters.FilterPlatform = { switch platform { case .ios: return .ios case .macOs: return .macOs case .tvOs: return .tvOs case .visionOs: return .visionOs } }() let endpoint = APIEndpoint.v1.apps.id(app).appStoreVersions .get( parameters: .init( filterAppVersionState: [.processingForDistribution, .readyForDistribution, .pendingAppleRelease], filterPlatform: [platform], fieldsAppStoreVersionLocalizations: [.promotionalText, .locale], limit: 1, include: [.appStoreVersionLocalizations] ) ) let response = try await provider.request(endpoint) let localizations = response.included ?. compactMap { item in if case .appStoreVersionLocalization(let localization) = item { return localization } return nil } let easyAccessLocalizations: [String: AppStoreVersionLocalization] = localizations? .reduce(into: [String: AppStoreVersionLocalization](), { $0[$1.id] = $1 }) ?? [:] let latestVersionLocalizations = response.data.first ? . relationships ?. appStoreVersionLocalizations ? . data? .reduce(into: [AppStoreLanguage: String]()) { partialResult, localization in if let matchedLocalization = easyAccessLocalizations[localization.id], let promotionalText = matchedLocalization.attributes ?. promotionalText, let language = AppStoreLanguage(rawValue: matchedLocalization.attributes ?. locale ? ? "") { partialResult[language] = promotionalText } } return latestVersionLocalizations ?? [:] }

Slide 53

Slide 53 text

func fetchAllVersionLocalizations(forVersion versionId: String) async throws - > [(String, AppStoreLanguage)] { let endpoint = APIEndpoint .v1 .appStoreVersions .id(versionId) .appStoreVersionLocalizations .get(parameters: .init(fieldsAppStoreVersionLocalizations: [.locale])) return try await provider.request(endpoint) .data .compactMap { localization in guard let locale = localization.attributes ?. locale, let language = AppStoreLanguage(rawValue: locale) else { return nil } return (localization.id, language) } }

Slide 54

Slide 54 text

func update( promotionalText: String?, forLanguage language: AppStoreLanguage, ofLocalization localization: String ) async throws { let attributes = AppStoreVersionLocalizationUpdateRequest.Data.Attributes( promotionalText: promotionalText ) let data = AppStoreVersionLocalizationUpdateRequest.Data( type: .appStoreVersionLocalizations, id: localization, attributes: attributes ) let request = AppStoreVersionLocalizationUpdateRequest(data: data) let endpoint = APIEndpoint .v1 .appStoreVersionLocalizations .id(localization) .patch(request) _ = try await provider.request(endpoint) }

Slide 55

Slide 55 text

func newVersion(forApp app: String, withPlatform platform: Platform, andVersion version: String) async throws { let lastAvailablePromotionalTexts = try await getLatestLiveVersionPromotionalText(forApp: app, withPlatform: platform) let newVersionId = try await createVersion(forApp: app, withPlatform: platform, andVersion: "1.0.0") try await withThrowingTaskGroup(of: Void.self) { taskGroup in let allVersionLocalizations = try await fetchAllVersionLocalizations(forVersion: newVersionId) for (id, language) in allVersionLocalizations { taskGroup.addTask { try await update( promotionalText: lastAvailablePromotionalTexts[language], forLanguage: language, ofLocalization: id ) } } } }

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

Reading customer reviews Reading customer reviews

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

func getReviews( sort: ReviewSortOrder = .dateDescending, after previousPage: URL? = nil ) async throws - > ReviewsResponse { let request = APIEndpoint.v1.apps.id(self.id).customerReviews .get( parameters: .init( sort: [sort.apiSort], fieldsCustomerReviews: [.body, .createdDate, .rating, .response, .reviewerNickname, .territory, .title], fieldsCustomerReviewResponses: [.review, .lastModifiedDate, .responseBody,.state], limit: 100, include: [.response] ) ) let reviews: CustomerReviewsResponse if let previousPage { let urlComponents = URLComponents(url: previousPage, resolvingAgainstBaseURL: true) let paginatedRequest = Request( path: urlComponents ?. path ?? "", method: request.method, query: urlComponents ? . queryItems ? . map { ($0.name, $0.value) }, id: request.id ? ? "paginated_customer_reviews" ) reviews = try await provider.request(paginatedRequest) } else { reviews = try await provider.request(request) } let customerReviews = reviews.data.map { reviewData in let response = reviews.included ?. first { $0.id == reviewData.relationships ?. response ?. data ?. id } return Review(review: reviewData, response: response) } let nextPageURL: URL? = { guard let nextPageString = reviews.links.next else { return nil } return URL(string: nextPageString) }() return ReviewsResponse(reviews: customerReviews, total: reviews.meta ?. paging.total, nextPage: nextPageURL) }

Slide 63

Slide 63 text

func getReviews( sort: ReviewSortOrder = .dateDescending, after previousPage: URL? = nil ) async throws - > ReviewsResponse { let request = APIEndpoint.v1.apps.id(self.id).customerReviews .get( parameters: .init( sort: [sort.apiSort], fieldsCustomerReviews: [.body, .createdDate, .rating, .response, .reviewerNickname, .territory, .title], fieldsCustomerReviewResponses: [.review, .lastModifiedDate, .responseBody,.state], limit: 100, include: [.response] ) ) let reviews: CustomerReviewsResponse if let previousPage { let urlComponents = URLComponents(url: previousPage, resolvingAgainstBaseURL: true) let paginatedRequest = Request( path: urlComponents ?. path ?? "", method: request.method, query: urlComponents ? . queryItems ? . map { ($0.name, $0.value) }, id: request.id ? ? "paginated_customer_reviews" ) reviews = try await provider.request(paginatedRequest) } else { reviews = try await provider.request(request) } let customerReviews = reviews.data.map { reviewData in let response = reviews.included ?. first { $0.id == reviewData.relationships ?. response ?. data ?. id } return Review(review: reviewData, response: response) } let nextPageURL: URL? = { guard let nextPageString = reviews.links.next else { return nil } return URL(string: nextPageString) }() return ReviewsResponse(reviews: customerReviews, total: reviews.meta ?. paging.total, nextPage: nextPageURL) }

Slide 64

Slide 64 text

func getReviews( sort: ReviewSortOrder = .dateDescending, after previousPage: URL? = nil ) async throws - > ReviewsResponse { let request = APIEndpoint.v1.apps.id(self.id).customerReviews .get( parameters: .init( sort: [sort.apiSort], fieldsCustomerReviews: [.body, .createdDate, .rating, .response, .reviewerNickname, .territory, .title], fieldsCustomerReviewResponses: [.review, .lastModifiedDate, .responseBody,.state], limit: 100, include: [.response] ) ) let reviews: CustomerReviewsResponse if let previousPage { let urlComponents = URLComponents(url: previousPage, resolvingAgainstBaseURL: true) let paginatedRequest = Request( path: urlComponents ?. path ?? "", method: request.method, query: urlComponents ? . queryItems ? . map { ($0.name, $0.value) }, id: request.id ? ? "paginated_customer_reviews" ) reviews = try await provider.request(paginatedRequest) } else { reviews = try await provider.request(request) } let customerReviews = reviews.data.map { reviewData in let response = reviews.included ?. first { $0.id == reviewData.relationships ?. response ?. data ?. id } return Review(review: reviewData, response: response) } let nextPageURL: URL? = { guard let nextPageString = reviews.links.next else { return nil } return URL(string: nextPageString) }() return ReviewsResponse(reviews: customerReviews, total: reviews.meta ?. paging.total, nextPage: nextPageURL) }

Slide 65

Slide 65 text

func getReviews( sort: ReviewSortOrder = .dateDescending, after previousPage: URL? = nil ) async throws - > ReviewsResponse { let request = APIEndpoint.v1.apps.id(self.id).customerReviews .get( parameters: .init( sort: [sort.apiSort], fieldsCustomerReviews: [.body, .createdDate, .rating, .response, .reviewerNickname, .territory, .title], fieldsCustomerReviewResponses: [.review, .lastModifiedDate, .responseBody,.state], limit: 100, include: [.response] ) ) let reviews: CustomerReviewsResponse if let previousPage { let urlComponents = URLComponents(url: previousPage, resolvingAgainstBaseURL: true) let paginatedRequest = Request( path: urlComponents ?. path ?? "", method: request.method, query: urlComponents ? . queryItems ? . map { ($0.name, $0.value) }, id: request.id ? ? "paginated_customer_reviews" ) reviews = try await provider.request(paginatedRequest) } else { reviews = try await provider.request(request) } let customerReviews = reviews.data.map { reviewData in let response = reviews.included ?. first { $0.id == reviewData.relationships ?. response ?. data ?. id } return Review(review: reviewData, response: response) } let nextPageURL: URL? = { guard let nextPageString = reviews.links.next else { return nil } return URL(string: nextPageString) }() return ReviewsResponse(reviews: customerReviews, total: reviews.meta ?. paging.total, nextPage: nextPageURL) }

Slide 66

Slide 66 text

func getReviews( sort: ReviewSortOrder = .dateDescending, after previousPage: URL? = nil ) async throws - > ReviewsResponse { let request = APIEndpoint.v1.apps.id(self.id).customerReviews .get( parameters: .init( sort: [sort.apiSort], fieldsCustomerReviews: [.body, .createdDate, .rating, .response, .reviewerNickname, .territory, .title], fieldsCustomerReviewResponses: [.review, .lastModifiedDate, .responseBody,.state], limit: 100, include: [.response] ) ) let reviews: CustomerReviewsResponse if let previousPage { let urlComponents = URLComponents(url: previousPage, resolvingAgainstBaseURL: true) let paginatedRequest = Request( path: urlComponents ?. path ?? "", method: request.method, query: urlComponents ? . queryItems ? . map { ($0.name, $0.value) }, id: request.id ? ? "paginated_customer_reviews" ) reviews = try await provider.request(paginatedRequest) } else { reviews = try await provider.request(request) } let customerReviews = reviews.data.map { reviewData in let response = reviews.included ?. first { $0.id == reviewData.relationships ?. response ?. data ?. id } return Review(review: reviewData, response: response) } let nextPageURL: URL? = { guard let nextPageString = reviews.links.next else { return nil } return URL(string: nextPageString) }() return ReviewsResponse(reviews: customerReviews, total: reviews.meta ?. paging.total, nextPage: nextPageURL) }

Slide 67

Slide 67 text

func getReviews( sort: ReviewSortOrder = .dateDescending, after previousPage: URL? = nil ) async throws - > ReviewsResponse { let request = APIEndpoint.v1.apps.id(self.id).customerReviews .get( parameters: .init( sort: [sort.apiSort], fieldsCustomerReviews: [.body, .createdDate, .rating, .response, .reviewerNickname, .territory, .title], fieldsCustomerReviewResponses: [.review, .lastModifiedDate, .responseBody,.state], limit: 100, include: [.response] ) ) let reviews: CustomerReviewsResponse if let previousPage { let urlComponents = URLComponents(url: previousPage, resolvingAgainstBaseURL: true) let paginatedRequest = Request( path: urlComponents ?. path ?? "", method: request.method, query: urlComponents ? . queryItems ? . map { ($0.name, $0.value) }, id: request.id ? ? "paginated_customer_reviews" ) reviews = try await provider.request(paginatedRequest) } else { reviews = try await provider.request(request) } let customerReviews = reviews.data.map { reviewData in let response = reviews.included ?. first { $0.id == reviewData.relationships ?. response ?. data ?. id } return Review(review: reviewData, response: response) } let nextPageURL: URL? = { guard let nextPageString = reviews.links.next else { return nil } return URL(string: nextPageString) }() return ReviewsResponse(reviews: customerReviews, total: reviews.meta ?. paging.total, nextPage: nextPageURL) }

Slide 68

Slide 68 text

func getReviews( sort: ReviewSortOrder = .dateDescending, after previousPage: URL? = nil ) async throws - > ReviewsResponse { let request = APIEndpoint.v1.apps.id(self.id).customerReviews .get( parameters: .init( sort: [sort.apiSort], fieldsCustomerReviews: [.body, .createdDate, .rating, .response, .reviewerNickname, .territory, .title], fieldsCustomerReviewResponses: [.review, .lastModifiedDate, .responseBody,.state], limit: 100, include: [.response] ) ) let reviews: CustomerReviewsResponse if let previousPage { let urlComponents = URLComponents(url: previousPage, resolvingAgainstBaseURL: true) let paginatedRequest = Request( path: urlComponents ?. path ?? "", method: request.method, query: urlComponents ? . queryItems ? . map { ($0.name, $0.value) }, id: request.id ? ? "paginated_customer_reviews" ) reviews = try await provider.request(paginatedRequest) } else { reviews = try await provider.request(request) } let customerReviews = reviews.data.map { reviewData in let response = reviews.included ?. first { $0.id == reviewData.relationships ?. response ?. data ?. id } return Review(review: reviewData, response: response) } let nextPageURL: URL? = { guard let nextPageString = reviews.links.next else { return nil } return URL(string: nextPageString) }() return ReviewsResponse(reviews: customerReviews, total: reviews.meta ?. paging.total, nextPage: nextPageURL) }

Slide 69

Slide 69 text

Uploading assets in bulk Uploading assets in bulk

Slide 70

Slide 70 text

struct ScreenshotSet { let id: String let type: ScreenshotDisplayType } func uploadScreenshot(_ file: URL, to set: ScreenshotSet) async throws { let imageData = try Data(contentsOf: file) }

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

https://developer.apple.com/documentation/appstoreconnectapi/uploading_assets_to_app_store_connect

Slide 73

Slide 73 text

func uploadScreenshot(_ file: URL, to set: ScreenshotSet) async throws { let imageData = try Data(contentsOf: file) // 1 let (reservationId, uploadRequests) = try await createReservation( inSet: set.id, fileName: file.lastPathComponent, imageData: imageData ) // 2 try await uploadAssets(with: uploadRequests) // 3 try await commitReservations(for: reservationId, with: imageData) }

Slide 74

Slide 74 text

func uploadScreenshot(_ file: URL, to set: ScreenshotSet) async throws { let imageData = try Data(contentsOf: file) // 1 let (reservationId, uploadRequests) = try await createReservation( inSet: set.id, fileName: file.lastPathComponent, imageData: imageData ) // 2 try await uploadAssets(with: uploadRequests) // 3 try await commitReservations(for: reservationId, with: imageData) }

Slide 75

Slide 75 text

func uploadScreenshot(_ file: URL, to set: ScreenshotSet) async throws { let imageData = try Data(contentsOf: file) // 1 let (reservationId, uploadRequests) = try await createReservation( inSet: set.id, fileName: file.lastPathComponent, imageData: imageData ) // 2 try await uploadAssets(with: uploadRequests) // 3 try await commitReservations(for: reservationId, with: imageData) }

Slide 76

Slide 76 text

func createReservation(inSet set: String, fileName: String, imageData: Data) async throws -> (String, [URLRequest]) { let screenshotSetData = AppScreenshotCreateRequest.Data.Relationships.AppScreenshotSet.Data(type: .appScreenshotSets, id: set) let screenshotSet = AppScreenshotCreateRequest.Data.Relationships.AppScreenshotSet(data: screenshotSetData) let relationships = AppScreenshotCreateRequest.Data.Relationships(appScreenshotSet: screenshotSet) let attributes = AppScreenshotCreateRequest.Data.Attributes(fileSize: imageData.count,fileName: fileName) let data = AppScreenshotCreateRequest.Data(type: .appScreenshots, attributes: attributes, relationships: relationships) let body = AppScreenshotCreateRequest(data: data) let reservationResponse = try await provider.request(APIEndpoint.v1.appScreenshots.post(body)) let requests = reservationResponse.data.attributes ? . uploadOperations? .compactMap { uploadOperation - > URLRequest? in guard let urlString = uploadOperation.url, let url = URL(string: urlString), let method = uploadOperation.method, let offset = uploadOperation.offset, let length = uploadOperation.length else { return nil } let chunk = imageData[offset ..< (offset + length)] var request = URLRequest(url: url) request.httpMethod = method for header in (uploadOperation.requestHeaders ?? []) { if let name = header.name { request.setValue(header.value, forHTTPHeaderField: name) } } request.httpBody = chunk return request } ?? [] return (reservationResponse.data.id, requests) }

Slide 77

Slide 77 text

func createReservation(inSet set: String, fileName: String, imageData: Data) async throws -> (String, [URLRequest]) { let screenshotSetData = AppScreenshotCreateRequest.Data.Relationships.AppScreenshotSet.Data(type: .appScreenshotSets, id: set) let screenshotSet = AppScreenshotCreateRequest.Data.Relationships.AppScreenshotSet(data: screenshotSetData) let relationships = AppScreenshotCreateRequest.Data.Relationships(appScreenshotSet: screenshotSet) let attributes = AppScreenshotCreateRequest.Data.Attributes(fileSize: imageData.count,fileName: fileName) let data = AppScreenshotCreateRequest.Data(type: .appScreenshots, attributes: attributes, relationships: relationships) let body = AppScreenshotCreateRequest(data: data) let reservationResponse = try await provider.request(APIEndpoint.v1.appScreenshots.post(body)) let requests = reservationResponse.data.attributes ? . uploadOperations? .compactMap { uploadOperation - > URLRequest? in guard let urlString = uploadOperation.url, let url = URL(string: urlString), let method = uploadOperation.method, let offset = uploadOperation.offset, let length = uploadOperation.length else { return nil } let chunk = imageData[offset ..< (offset + length)] var request = URLRequest(url: url) request.httpMethod = method for header in (uploadOperation.requestHeaders ?? []) { if let name = header.name { request.setValue(header.value, forHTTPHeaderField: name) } } request.httpBody = chunk return request } ?? [] return (reservationResponse.data.id, requests) }

Slide 78

Slide 78 text

func createReservation(inSet set: String, fileName: String, imageData: Data) async throws -> (String, [URLRequest]) { let screenshotSetData = AppScreenshotCreateRequest.Data.Relationships.AppScreenshotSet.Data(type: .appScreenshotSets, id: set) let screenshotSet = AppScreenshotCreateRequest.Data.Relationships.AppScreenshotSet(data: screenshotSetData) let relationships = AppScreenshotCreateRequest.Data.Relationships(appScreenshotSet: screenshotSet) let attributes = AppScreenshotCreateRequest.Data.Attributes(fileSize: imageData.count,fileName: fileName) let data = AppScreenshotCreateRequest.Data(type: .appScreenshots, attributes: attributes, relationships: relationships) let body = AppScreenshotCreateRequest(data: data) let reservationResponse = try await provider.request(APIEndpoint.v1.appScreenshots.post(body)) let requests = reservationResponse.data.attributes ? . uploadOperations? .compactMap { uploadOperation - > URLRequest? in guard let urlString = uploadOperation.url, let url = URL(string: urlString), let method = uploadOperation.method, let offset = uploadOperation.offset, let length = uploadOperation.length else { return nil } let chunk = imageData[offset ..< (offset + length)] var request = URLRequest(url: url) request.httpMethod = method for header in (uploadOperation.requestHeaders ?? []) { if let name = header.name { request.setValue(header.value, forHTTPHeaderField: name) } } request.httpBody = chunk return request } ?? [] return (reservationResponse.data.id, requests) }

Slide 79

Slide 79 text

func createReservation(inSet set: String, fileName: String, imageData: Data) async throws -> (String, [URLRequest]) { let screenshotSetData = AppScreenshotCreateRequest.Data.Relationships.AppScreenshotSet.Data(type: .appScreenshotSets, id: set) let screenshotSet = AppScreenshotCreateRequest.Data.Relationships.AppScreenshotSet(data: screenshotSetData) let relationships = AppScreenshotCreateRequest.Data.Relationships(appScreenshotSet: screenshotSet) let attributes = AppScreenshotCreateRequest.Data.Attributes(fileSize: imageData.count,fileName: fileName) let data = AppScreenshotCreateRequest.Data(type: .appScreenshots, attributes: attributes, relationships: relationships) let body = AppScreenshotCreateRequest(data: data) let reservationResponse = try await provider.request(APIEndpoint.v1.appScreenshots.post(body)) let requests = reservationResponse.data.attributes ? . uploadOperations? .compactMap { uploadOperation - > URLRequest? in guard let urlString = uploadOperation.url, let url = URL(string: urlString), let method = uploadOperation.method, let offset = uploadOperation.offset, let length = uploadOperation.length else { return nil } let chunk = imageData[offset ..< (offset + length)] var request = URLRequest(url: url) request.httpMethod = method for header in (uploadOperation.requestHeaders ?? []) { if let name = header.name { request.setValue(header.value, forHTTPHeaderField: name) } } request.httpBody = chunk return request } ?? [] return (reservationResponse.data.id, requests) }

Slide 80

Slide 80 text

func createReservation(inSet set: String, fileName: String, imageData: Data) async throws -> (String, [URLRequest]) { let screenshotSetData = AppScreenshotCreateRequest.Data.Relationships.AppScreenshotSet.Data(type: .appScreenshotSets, id: set) let screenshotSet = AppScreenshotCreateRequest.Data.Relationships.AppScreenshotSet(data: screenshotSetData) let relationships = AppScreenshotCreateRequest.Data.Relationships(appScreenshotSet: screenshotSet) let attributes = AppScreenshotCreateRequest.Data.Attributes(fileSize: imageData.count,fileName: fileName) let data = AppScreenshotCreateRequest.Data(type: .appScreenshots, attributes: attributes, relationships: relationships) let body = AppScreenshotCreateRequest(data: data) let reservationResponse = try await provider.request(APIEndpoint.v1.appScreenshots.post(body)) let requests = reservationResponse.data.attributes ? . uploadOperations? .compactMap { uploadOperation - > URLRequest? in guard let urlString = uploadOperation.url, let url = URL(string: urlString), let method = uploadOperation.method, let offset = uploadOperation.offset, let length = uploadOperation.length else { return nil } let chunk = imageData[offset ..< (offset + length)] var request = URLRequest(url: url) request.httpMethod = method for header in (uploadOperation.requestHeaders ?? []) { if let name = header.name { request.setValue(header.value, forHTTPHeaderField: name) } } request.httpBody = chunk return request } ?? [] return (reservationResponse.data.id, requests) }

Slide 81

Slide 81 text

func createReservation(inSet set: String, fileName: String, imageData: Data) async throws -> (String, [URLRequest]) { let screenshotSetData = AppScreenshotCreateRequest.Data.Relationships.AppScreenshotSet.Data(type: .appScreenshotSets, id: set) let screenshotSet = AppScreenshotCreateRequest.Data.Relationships.AppScreenshotSet(data: screenshotSetData) let relationships = AppScreenshotCreateRequest.Data.Relationships(appScreenshotSet: screenshotSet) let attributes = AppScreenshotCreateRequest.Data.Attributes(fileSize: imageData.count,fileName: fileName) let data = AppScreenshotCreateRequest.Data(type: .appScreenshots, attributes: attributes, relationships: relationships) let body = AppScreenshotCreateRequest(data: data) let reservationResponse = try await provider.request(APIEndpoint.v1.appScreenshots.post(body)) let requests = reservationResponse.data.attributes ? . uploadOperations? .compactMap { uploadOperation - > URLRequest? in guard let urlString = uploadOperation.url, let url = URL(string: urlString), let method = uploadOperation.method, let offset = uploadOperation.offset, let length = uploadOperation.length else { return nil } let chunk = imageData[offset ..< (offset + length)] var request = URLRequest(url: url) request.httpMethod = method for header in (uploadOperation.requestHeaders ?? []) { if let name = header.name { request.setValue(header.value, forHTTPHeaderField: name) } } request.httpBody = chunk return request } ?? [] return (reservationResponse.data.id, requests) }

Slide 82

Slide 82 text

func uploadScreenshot(_ file: URL, to set: ScreenshotSet) async throws { let imageData = try Data(contentsOf: file) // 1 let (reservationId, uploadRequests) = try await createReservation( inSet: set.id, fileName: file.lastPathComponent, imageData: imageData ) // 2 try await uploadAssets(with: uploadRequests) // 3 try await commitReservations(for: reservationId, with: imageData) }

Slide 83

Slide 83 text

func uploadAssets(with requests: [URLRequest]) async throws { let session = URLSession.shared _ = try await withThrowingTaskGroup(of: Data.self, returning: [Data].self) { taskGroup in for request in requests { taskGroup.addTask { let (data, _) = try await session.data(for: request) return data } } var responses = [Data]() for try await result in taskGroup { responses.append(result) } return responses } }

Slide 84

Slide 84 text

func uploadAssets(with requests: [URLRequest]) async throws { let session = URLSession.shared _ = try await withThrowingTaskGroup(of: Data.self, returning: [Data].self) { taskGroup in for request in requests { taskGroup.addTask { let (data, _) = try await session.data(for: request) return data } } var responses = [Data]() for try await result in taskGroup { responses.append(result) } return responses } }

Slide 85

Slide 85 text

func uploadAssets(with requests: [URLRequest]) async throws { let session = URLSession.shared _ = try await withThrowingTaskGroup(of: Data.self, returning: [Data].self) { taskGroup in for request in requests { taskGroup.addTask { let (data, _) = try await session.data(for: request) return data } } var responses = [Data]() for try await result in taskGroup { responses.append(result) } return responses } }

Slide 86

Slide 86 text

func uploadScreenshot(_ file: URL, to set: ScreenshotSet) async throws { let imageData = try Data(contentsOf: file) // 1 let (reservationId, uploadRequests) = try await createReservation( inSet: set.id, fileName: file.lastPathComponent, imageData: imageData ) // 2 try await uploadAssets(with: uploadRequests) // 3 try await commitReservations(for: reservationId, with: imageData) }

Slide 87

Slide 87 text

import Crypto func commitReservations(for reservation: String, with imageData: Data) async throws { let bytes = Array(Crypto.Insecure.MD5.hash(data: imageData).makeIterator()) let checksum = bytes.map { String(format: "%02x", $0) }.joined() let screenshotUpdateRequestAttributes = AppScreenshotUpdateRequest.Data.Attributes( sourceFileChecksum: checksum, isUploaded: true ) let screenshotUpdateRequestData = AppScreenshotUpdateRequest.Data( type: .appScreenshots, id: reservation, attributes: screenshotUpdateRequestAttributes ) let screenshotUpdateRequest = AppScreenshotUpdateRequest(data: screenshotUpdateRequestData) let reservationCommitment = APIEndpoint .v1 .appScreenshots .id(reservation) .patch(screenshotUpdateRequest) _ = try await provider.request(reservationCommitment) }

Slide 88

Slide 88 text

import Crypto func commitReservations(for reservation: String, with imageData: Data) async throws { let bytes = Array(Crypto.Insecure.MD5.hash(data: imageData).makeIterator()) let checksum = bytes.map { String(format: "%02x", $0) }.joined() let screenshotUpdateRequestAttributes = AppScreenshotUpdateRequest.Data.Attributes( sourceFileChecksum: checksum, isUploaded: true ) let screenshotUpdateRequestData = AppScreenshotUpdateRequest.Data( type: .appScreenshots, id: reservation, attributes: screenshotUpdateRequestAttributes ) let screenshotUpdateRequest = AppScreenshotUpdateRequest(data: screenshotUpdateRequestData) let reservationCommitment = APIEndpoint .v1 .appScreenshots .id(reservation) .patch(screenshotUpdateRequest) _ = try await provider.request(reservationCommitment) }

Slide 89

Slide 89 text

import Crypto func commitReservations(for reservation: String, with imageData: Data) async throws { let bytes = Array(Crypto.Insecure.MD5.hash(data: imageData).makeIterator()) let checksum = bytes.map { String(format: "%02x", $0) }.joined() let screenshotUpdateRequestAttributes = AppScreenshotUpdateRequest.Data.Attributes( sourceFileChecksum: checksum, isUploaded: true ) let screenshotUpdateRequestData = AppScreenshotUpdateRequest.Data( type: .appScreenshots, id: reservation, attributes: screenshotUpdateRequestAttributes ) let screenshotUpdateRequest = AppScreenshotUpdateRequest(data: screenshotUpdateRequestData) let reservationCommitment = APIEndpoint .v1 .appScreenshots .id(reservation) .patch(screenshotUpdateRequest) _ = try await provider.request(reservationCommitment) }

Slide 90

Slide 90 text

No content

Slide 91

Slide 91 text

No content

Slide 92

Slide 92 text

extension NSImage { func removeAlphaChannel() -> NSImage? { guard let cgImage = self.cgImage(forProposedRect: nil, context: nil, hints: nil), let colorSpace = cgImage.colorSpace, let context = CGContext( data: nil, width: cgImage.width, height: cgImage.height, bitsPerComponent: cgImage.bitsPerComponent, bytesPerRow: cgImage.bytesPerRow, space: colorSpace, bitmapInfo: CGImageAlphaInfo.noneSkipLast.rawValue ) else { return nil } context.draw(cgImage, in: CGRect(x: 0, y: 0, width: context.width, height: context.height)) guard let newCg = context.makeImage() else { return nil } return NSImage(cgImage: newCg, size: .zero) } }

Slide 93

Slide 93 text

No content

Slide 94

Slide 94 text

Ship Easy Ship Fast Automate manual processes App Store Connect API Build your own automations Customer Reviews Multiple locales Handle content for multiple platforms Automatically upload assets in bulk

Slide 95

Slide 95 text

Ship Easy Ship Fast

Slide 96

Slide 96 text

Ship Easy Ship Fast Say hi! 👋