Offering, completing, and restoring in-app purchases
At a glance
| Item | Summary |
|---|---|
| Purpose | Fetch, display, purchase, validate, and finish transactions in your app. |
| App architecture | A C/Objective-C header, Objective-C, Swift sample bundle with entry-bearing project variants Objective-C, Swift, each leading to StoreKit APIs. |
| Main patterns | View-controller organization, Protocol-oriented abstraction, Delegate or data-source callbacks |
| Project style | 75 scanned source file(s) across C/Objective-C header, Objective-C, Swift, organized around ranked entry, type, and file boundaries. |
| Execution model | Source-visible boundaries: DispatchQueue.main.async; none alone proves a background thread. |
| State/event model | No structured observation or publisher-scheduling marker indexed. |
| Key frameworks/packages | StoreKit, UIKit, Cocoa, Foundation; these are source dependencies, not architecture labels. |
Project structure
Source bundle/
├── Objective-C/
│ ├── iOS/
│ │ ├── main.m
│ │ └── ParentViewController.m
│ ├── macOS/
│ │ ├── main.m
│ │ ├── AppDelegate.m
│ │ └── MainViewController.m
│ ├── tvOS/
│ │ ├── main.m
│ │ └── TabBarViewController.m
│ └── Common/
│ ├── StoreManager.m
│ └── StoreObserver.m
└── Swift/
├── Common/
│ └── AppProtocols.swift
├── iOS/
│ └── ParentViewController.swift
└── tvOS/
└── TabBarViewController.swift
Structure observations
- Architecturally prominent files are ranked from entry points and role-named declarations; resource-only paths are omitted.
- Primary languages: C/Objective-C header, Objective-C, Swift.
- The verified tree contains 27 project/configuration file(s) and 62 source declaration(s).
Overall architecture
flowchart LR
Bundle["Sample bundle"]
V1["Objective-C"]
V2["Swift"]
Boundary["StoreKit APIs"]
Bundle --> V1
V1 --> Boundary
Bundle --> V2
V2 --> Boundary
Reference code
Objective-C/iOS/main.m:11 — architecture anchor
int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}Interpretation
The branches represent separate entry-bearing project variants in the downloaded bundle, not runtime calls between those variants. Each branch is intentionally collapsed at the documented framework boundary; the detailed target-local flow remains in the cited files. Ownership is claimed only where the next section cites a stored property or assignment.
Ownership and state
classDiagram
StoreManager o-- NSMutableArray : availableProducts
StoreManager o-- NSMutableArray : invalidProductIdentifiers
StoreManager o-- SKProductsRequest : productRequest
StoreObserver o-- BOOL : hasRestorablePurchases
Ownership evidence
Objective-C/Common/StoreManager.m:12 — stored dependency or nearest verified ownership anchor
@interface StoreManager()<SKRequestDelegate, SKProductsRequestDelegate>
// ...
@property (strong) NSMutableArray *availableProducts;
// ...
@end| Owner | Object or state | Relationship | Mutation authority |
|---|---|---|---|
StoreManager |
NSMutableArray (availableProducts) |
retains or copies an assigned value | Owning Objective-C implementation |
StoreManager |
NSMutableArray (invalidProductIdentifiers) |
retains or copies an assigned value | Owning Objective-C implementation |
StoreManager |
SKProductsRequest (productRequest) |
retains or copies an assigned value | Owning Objective-C implementation |
StoreObserver |
BOOL (hasRestorablePurchases) |
stores or receives | Owning Objective-C implementation |
Composition arrows indicate a source-visible construction expression or locally owned value state; aggregation means the owner stores or receives a dependency without proving exclusive lifetime ownership.
Concurrency, scheduling, and thread safety
Evidence limit: actor isolation, async/await, or Task creation does not by itself prove background-thread execution; Sendable conformance alone does not prove thread-safe mutation.
| Concern | Source mechanism | Verified placement or handoff | Evidence |
|---|---|---|---|
| Queue scheduling | DispatchQueue.main.async |
The source addresses the main dispatch queue. | Swift/Common/StoreManager.swift:108 |
@MainActor/MainActor.run, DispatchQueue.main, and RunLoop.main are reported as distinct isolation, queue, and event-loop mechanisms. A plain Task is kept separate from Task.detached; neither is labeled as a background thread.
Reference code
Swift/Common/StoreManager.swift:108 — representative execution boundary
DispatchQueue.main.async {
self.delegate?.storeManagerDidReceiveResponse(self.storeResponse)
}State propagation, frameworks, and dependencies
Evidence limit: an import proves a source-level compilation dependency at the cited line; it does not prove runtime use, architectural adoption, or whether a Swift package is a direct application dependency.
| Category | Mechanism or module | Verified role | Evidence |
|---|---|---|---|
| Source import | StoreKit |
The cited file imports this module; runtime use and architectural role are not inferred. | Swift/Common/AppExtensions.swift:14 |
| Source import | UIKit |
The cited file imports this module; runtime use and architectural role are not inferred. | Swift/Common/AppExtensions.swift:11 |
| Source import | Cocoa |
The cited file imports this module; runtime use and architectural role are not inferred. | Swift/Common/AppExtensions.swift:9 |
| Source import | Foundation |
The cited file imports this module; runtime use and architectural role are not inferred. | Swift/Common/AppDataTypes.swift:8 |
receive(on:) describes downstream delivery scheduling, while subscribe(on:) describes upstream subscription/request/cancel scheduling. An import Combine alone establishes neither behavior nor a Store, reducer, Redux, or other application architecture.
Class and protocol design
Swift/Common/AppProtocols.swift:12 — representative type boundary
protocol DiscloseView {
func show()
func hide()
}| Type | Responsibility | Depends on or conforms to |
|---|---|---|
AppDelegate |
Receives callback-driven events | UIResponder, UIApplicationDelegate |
AppDelegate |
Receives callback-driven events | NSObject, NSApplicationDelegate, NSUserInterfaceValidations |
AppDelegate |
Receives callback-driven events | UIResponder, UIApplicationDelegate |
DiscloseView |
Defines a capability or collaboration contract | Concrete collaborators/imported frameworks |
StoreManagerDelegate |
Defines a capability or collaboration contract | AnyObject |
StoreObserverDelegate |
Defines a capability or collaboration contract | AnyObject |
SettingsDelegate |
Defines a capability or collaboration contract | AnyObject |
IAPTableViewDataSource |
Defines a capability or collaboration contract | NSObject |
ParentViewController |
View lifecycle, callbacks, and feature coordination | UIViewController |
TabBarViewController |
View lifecycle, callbacks, and feature coordination | UITabBarController |
The source explicitly defines local protocol relationships: BaseViewController → IAPTableViewDataSource, NSView → DiscloseView, UIView → DiscloseView, UIBarItem → EnableItem, ParentViewController → StoreManagerDelegate, ParentViewController → StoreObserverDelegate.
Access control
| Symbol | Access | Verified effect | Likely rationale |
|---|---|---|---|
data (Objective-C/Common/BaseViewController.h:12) |
header-visible |
The declaration is exposed to translation units that import the header. | Inference: declare a contract needed by other Objective-C/C translation units. |
name (Objective-C/Common/Section.h:12) |
header-visible |
The declaration is exposed to translation units that import the header. | Inference: declare a contract needed by other Objective-C/C translation units. |
elements (Objective-C/Common/Section.h:15) |
header-visible |
The declaration is exposed to translation units that import the header. | Inference: declare a contract needed by other Objective-C/C translation units. |
message (Objective-C/Common/StoreManager.h:15) |
header-visible |
The declaration is exposed to translation units that import the header. | Inference: declare a contract needed by other Objective-C/C translation units. |
Reference code
Objective-C/Common/BaseViewController.h:12 — representative boundary
@interface BaseViewController : UITableViewController <IAPTableViewDataSource>
@property (strong) NSMutableArray *data;
@endSwift declarations without a modifier are internal; explicit private, fileprivate, private(set), public, or open entries above are interpreted by language semantics. Objective-C/C samples instead rely on header and implementation boundaries, which are not equivalent to Swift lexical privacy.
Logic ownership and placement
| Logic | Owning type or file | Placement rationale |
|---|---|---|
| View lifecycle, callbacks, and feature coordination | BaseViewController, MainViewController, MessagesViewController, ParentViewController |
The source’s Controller suffix makes this role explicit. |
| Supplies data through a callback contract | IAPTableViewDataSource |
The source’s DataSource suffix makes this role explicit. |
| Receives callback-driven events | AppDelegate, SettingsDelegate, StoreManagerDelegate, StoreObserverDelegate |
The source’s Delegate suffix makes this role explicit. |
| Long-lived feature or framework coordination | StoreManager |
The source’s Manager suffix makes this role explicit. |
| Observes and relays feature changes | StoreObserver |
The source’s Observer suffix makes this role explicit. |
| User-interface presentation and input forwarding | DiscloseView |
The source’s View suffix makes this role explicit. |
Design patterns
| Pattern | Source evidence | Purpose or tradeoff |
|---|---|---|
| View-controller organization | Objective-C/Common/BaseViewController.h:11 |
A controller is the verified coordination boundary; this is MVC-style only where a separate model is present. |
| Protocol-oriented abstraction | Objective-C/Common/BaseViewController.h:11 |
A local protocol and concrete conformance create an explicit capability boundary. |
| Delegate or data-source callbacks | Objective-C/Common/BaseViewController.h:11 |
Callback protocols invert event delivery back into the sample’s owner. |
Main application flow
sequenceDiagram
participant StoreManager
participant storeResponse
participant NSMutableArray
participant Section
participant NSNotificationCenter
StoreManager->>storeResponse: removeAllObjects()
StoreManager->>NSMutableArray: arrayWithArray()
StoreManager->>Section: initWithName()
StoreManager->>storeResponse: addObject()
StoreManager->>NSMutableArray: arrayWithArray()
StoreManager->>Section: initWithName()
StoreManager->>storeResponse: addObject()
StoreManager->>NSNotificationCenter: postNotificationName()
Reference code
Objective-C/Common/StoreManager.m:82 — productsRequest()
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {
if (self.storeResponse.count > 0) {
[self.storeResponse removeAllObjects];
}
// Contains products with identifiers that the App Store recognizes. As such, they are available for purchase.
if ((response.products).count > 0) {
self.availableProducts = [NSMutableArray arrayWithArray:response.products];
Section *section = [[Section alloc] initWithName:PCSProductsAvailableProducts elements:response.products];
[self.storeResponse addObject:section];
}
// invalidProductIdentifiers contains all product identifiers that the App Store doesn’t recognize.
if ((response.invalidProductIdentifiers).count > 0) {
self.invalidProductIdentifiers = [NSMutableArray arrayWithArray:response.invalidProductIdentifiers];
Section *section = [[Section alloc] initWithName:PCSProductsInvalidIdentifiers elements:response.invalidProductIdentifiers];
[self.storeResponse addObject:section];
}
if (self.storeResponse.count > 0) {
self.status = PCSStoreResponse;
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:PCSProductRequestNotification object:self];
});
}
}Naming conventions
- Types: Controller: BaseViewController, MainViewController, MessagesViewController, ParentViewController, PrimaryViewController; DataSource: IAPTableViewDataSource; Delegate: AppDelegate, SettingsDelegate, StoreManagerDelegate, StoreObserverDelegate; Manager: StoreManager; Observer: StoreObserver; View: DiscloseView.
- Protocols:
DiscloseView,StoreManagerDelegate,StoreObserverDelegate,SettingsDelegate,IAPTableViewDataSource,EnableItem. - Methods:
sharedInstance,init,startProductRequestWithIdentifiers,fetchProductsMatchingIdentifiers,productsRequest,request,titleMatchingIdentifier,titleMatchingPaymentTransaction. - Files:
Objective-C/Common/StoreManager.m,Objective-C/Common/StoreObserver.m,Objective-C/iOS/ParentViewController.m,Objective-C/macOS/AppDelegate.m,Objective-C/macOS/MainViewController.m,Objective-C/tvOS/TabBarViewController.m.
Architecture takeaways
mainis the main source-visible entry or composition anchor for this sample.- Framework work reaches StoreKit, UIKit, Cocoa through a deliberately small high-level chain; the detailed API graph remains inside the cited implementation files.
- Stored-property evidence identifies lifecycle collaboration; it does not by itself prove exclusive object ownership.
- Access-control conclusions separate verified language visibility from the likely design rationale.
- Local protocol relationships provide an explicit substitution boundary.
Source map
| Source file | Relevant symbols |
|---|---|
Objective-C/iOS/main.m |
Cited implementation, Feature implementation |
Objective-C/Common/StoreManager.m |
Cited implementation, StoreManager |
Swift/Common/AppProtocols.swift |
DiscloseView, EnableItem, StoreManagerDelegate, StoreObserverDelegate, SettingsDelegate |
Objective-C/Common/BaseViewController.h |
data, BaseViewController, Cited implementation |
Objective-C/Common/Section.h |
name, elements, Section |
Objective-C/Common/StoreManager.h |
message, StoreManager |
Swift/Common/StoreManager.swift |
DispatchQueue.main.async, StoreManager |
Swift/Common/AppExtensions.swift |
StoreKit, UIKit, Cocoa, func |
Swift/Common/AppDataTypes.swift |
Foundation, TransactionContentLabels, Messages, ProductIdentifiers, SectionType, Section, ViewControllerIdentifiers, ViewControllerNames |
Objective-C/macOS/main.m |
Feature implementation |
Objective-C/tvOS/main.m |
Feature implementation |
Objective-C/Common/StoreObserver.m |
StoreObserver |
Objective-C/iOS/ParentViewController.m |
ParentViewController |
Objective-C/macOS/AppDelegate.m |
AppDelegate |
Objective-C/macOS/MainViewController.m |
MainViewController |
Objective-C/tvOS/TabBarViewController.m |
TabBarViewController |