Manages autorenewable subscriptions for your iOS project.
OTHER License
The JCSubscriptionManager class provides a singleton that manages autorenewable subscriptions for an iOS app. It is a simple solution for apps with only one 'family' of autorenewable subscriptions.
JCSubscriptionManager uses the following:
ARC is required.
###Add to your project
Link StoreKit.framework
, Security.framework
, and SystemConfiguration.framework
.
Drag the SubscriptionManager
, RMStore
, Lockbox
, and Reachability
directories to your project.
Add OpenSSL includes (from RMStore) to your Target's Header Search Paths, e.g.:
$(SRCROOT)/RMStore/RMStore/Optional/openssl-1.0.1e/include
Edit ProductIdentifiers.plist
to include product identifiers for your autorenewable subscriptions.
Edit JCSubscriptionManagerConfigs.h
to customize settings.
Add to app delegate's -didFinishLaunching:withOptions:
[JCSubscriptionManager sharedManager];
###Set up server-side receipt verification Skip this step if your app supports only >= iOS 7, where the local app receipt is used for verification.
<<YOUR APPLE APP SECRET>>
in verifyReceipt.php
to your autorenewable subscription shared secret (from iTunesConnect > Manage Your Apps > Manage In-App Purchases).verifyReceipt.php
to your verification server, the one you list as OWN_VERIFICATION_SERVER
in JCSubscriptionManagerConfigs.h
.###Get product data
Use this to populate your buy screen. Product data may not always be available (depending on connectivity) and the notification JCProductDataWasFetchedNotification
is sent on retrieval of product data.
- (NSArray *)products;
Also, a category on SKProduct to conveniently get a product's price formatted and localized.
- (NSString *)formattedPrice;
###Purchase a subscription
To purchase a subscription, use:
- (BOOL)buyProductWithIdentifier:(NSString *)productIdentifier
completion:(void (^)(BOOL success, NSError *transactionError))completion
error:(NSError *__autoreleasing *)pretransactionError;
This method returns NO if an error prevents the product being added to the payment queue.
You may also provide/remove access to subscription features by responding to the notifications JCSubscriptionWasMadeNotification
and JCSubscriptionExpiredNotification
, described below.
###Restore previous purchases
Restore previous transactions with:
- (BOOL)restorePreviousTransactionsWithCompletion:(void (^)(BOOL success, NSError *transactionError))completion
error:(NSError *__autoreleasing *)pretransactionError;
Again, this returns NO if the restore fails to start, and you will also be notified of changes in subscription status through the notifications described below.
###Check if user is subscribed
- (BOOL)isSubscriptionActive;
If you have multiple subscriptions in a 'family', this checks if any of them is active.
###Notifications
JCSubscriptionWasMadeNotification
: sent if an active subscription was verified when no previous subscription was found or a previous subscription lapsed.JCSubscriptionExpiredNotification
: sent if an active subscription has expired. JCSubscriptionManager will subsequently check if the subscription has been renewed.JCProductDataWasFetchedNotification
: sent when data on your subscriptions has been retrieved from iTunesConnect. This is when it is possible to populate your buy screen with info.###Testing
Edit ProductIdentifiers.plist
and JCSubscriptionManagerConfigs.h
in the example project, upload verifyReceipt.php
to your server (for < iOS7), and run the example project on a physical device to test your subscriptions.
A few things to point out:
###License
Copyright 2014 Joseph Chen
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.