Welcome to the documentation for the RMStore library! Here you will find detailed information and examples for integrating RMStore into your iOS apps. RMStore is a lightweight, dependency-free library for managing in-app purchases in iOS apps. It provides an easy-to-use interface for handling in-app purchases, receipt verification, and subscription management.
Installation
To install RMStore in your project, follow these steps:
- Open your project in Xcode.
- Navigate to your project’s root directory.
- Create a new directory called ‘Frameworks’ if it doesn’t already exist.
- Drag the ‘RMStore.framework’ file from the downloaded package into the ‘Frameworks’ directory.
- In Xcode, select your project’s target.
- Go to the ‘General’ tab and scroll down to the ‘Frameworks, Libraries, and Embedded Content’ section.
- Click the ‘+’ button and select ‘Add Other’.
- In the file picker, navigate to the ‘Frameworks’ directory and select ‘RMStore.framework’.
- Make sure the ‘Copy items if needed’ option is selected and click ‘Finish’.
Usage
Initialization
Before using RMStore, you need to initialize it with your StoreKit product identifiers. To do this, add the following code to your AppDelegate’s `didFinishLaunchingWithOptions` method:
<pre>[[RMStore defaultStore] addStoreObserver:[RMStoreAppReceiptVerifier verifier]];
NSSet *productIdentifiers = [NSSet setWithArray:@[
@"com.example.product1",
@"com.example.product2",
...
]];
[[RMStore defaultStore] requestProducts:productIdentifiers success:^(NSArray *products, NSArray *invalidProductIdentifiers) {
// Handle products and invalid product identifiers
} failure:^(NSError *error) {
// Handle error
}];
</pre>
Purchases
To initiate a purchase, you can use the following code example:
<pre>[[RMStore defaultStore] addPayment:productIdentifier success:^(SKPaymentTransaction *transaction) {
// Handle successful purchase
} failure:^(SKPaymentTransaction *transaction, NSError *error) {
// Handle failed purchase
}];
</pre>
Receipt Verification
RMStore includes a built-in receipt verification mechanism. It automatically validates the receipt with Apple’s servers whenever a purchase is made. To verify a receipt manually, you can call the following method:
<pre>[[RMStore defaultStore] verifyReceiptData:receiptData success:^{
// Receipt verification succeeded
} failure:^(NSError *error) {
// Receipt verification failed
}];
</pre>
Subscription Management
If you are working with auto-renewable subscriptions, RMStore provides convenient methods for managing subscription lifecycle events. For example, you can use the following code snippet to check if a user is subscribed:
<pre>if ([[RMStore defaultStore] isSubscribedToProduct:productIdentifier]) {
// User is subscribed
} else {
// User is not subscribed
}
</pre>
Conclusion
That’s it! You should now have a good understanding of how to integrate RMStore into your iOS apps. Feel free to explore the RMStore documentation for more detailed information and advanced usage examples. Happy coding!