Ignite Tools
Shared/Airship/Library/SubscriptionLib/UASubscriptionManager.h
00001 /*
00002  Copyright 2009-2011 Urban Airship Inc. All rights reserved.
00003 
00004  Redistribution and use in source and binary forms, with or without
00005  modification, are permitted provided that the following conditions are met:
00006 
00007  1. Redistributions of source code must retain the above copyright notice, this
00008  list of conditions and the following disclaimer.
00009 
00010  2. Redistributions in binaryform must reproduce the above copyright notice,
00011  this list of conditions and the following disclaimer in the documentation
00012  and/or other materials provided withthe distribution.
00013 
00014  THIS SOFTWARE IS PROVIDED BY THE URBAN AIRSHIP INC``AS IS'' AND ANY EXPRESS OR
00015  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00016  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
00017  EVENT SHALL URBAN AIRSHIP INC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
00018  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00019  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00020  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00021  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00022  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00023  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00024  */
00025 
00026 #import <Foundation/Foundation.h>
00027 
00028 #import "UAGlobal.h"
00029 #import "UAObservable.h"
00030 
00031 @class UASubscriptionProduct;
00032 @class UASubscriptionObserver;
00033 @class UASubscriptionInventory;
00034 @class UASubscriptionContent;
00035 @class UASubscriptionDownloadManager;
00036 
00037 #define SUBSCRIPTION_UI_CLASS @"UASubscriptionUI"
00038 
00039 UA_VERSION_INTERFACE(SubscriptionVersion)
00040 
00041 // Error failure messages for use with inventoryUpdateFailedWithError:
00043 extern NSString * const UASubscriptionPurchaseInventoryFailure;
00044 
00046 extern NSString * const UASubscriptionContentInventoryFailure;
00047 
00049 extern NSString * const UASubscriptionProductInventoryFailure;
00050 
00051 @protocol UASubscriptionUIProtocol
00052 + (void)displaySubscription:(UIViewController *)viewController
00053                    animated:(BOOL)animated;
00054 + (void)hideSubscription;
00055 @end
00056 
00057 /*
00058  * Important:
00059  * Since subscription and its products are created only once,
00060  * so same instance during one execution.
00061  * But contents will be reloaded once new product is purchased,
00062  * so contents' instance will be changed
00063  */
00064 @protocol UASubscriptionManagerObserver <NSObject>
00065 @optional
00066 - (void)subscriptionWillEnterForeground;
00067 - (void)subscriptionWillEnterBackground;
00068 
00074 - (void)subscriptionsUpdated:(NSArray *)subscriptions;
00075 
00081 - (void)userSubscriptionsUpdated:(NSArray *)subscriptions;
00082 
00101 - (void)inventoryUpdateFailedWithError:(NSError *)error;
00102 
00103 - (void)downloadContentFinished:(UASubscriptionContent *)content;
00104 - (void)downloadContentFailed:(UASubscriptionContent *)content;
00105 
00111 - (void)purchaseProductFinished:(UASubscriptionProduct *)product;
00112 
00120 - (void)purchaseProductFailed:(UASubscriptionProduct *)product withError:(NSError *)error;
00121 
00129 - (void)restoreAutorenewablesFinished:(NSArray *)productsRestored;
00130 
00138 - (void)restoreAutorenewablesFailedWithError:(NSError *)error;
00139 
00147 - (void)restoreAutorenewableProductFailed:(UASubscriptionProduct *)product;
00148 @end
00149 
00159 @interface UASubscriptionManager : UAObservable {
00160   @private
00161     UASubscriptionDownloadManager *downloadManager;
00162     UASubscriptionInventory *inventory;
00163     UASubscriptionObserver *transactionObserver;
00164     UASubscriptionProduct *pendingProduct;//should be deprecated
00165 }
00166 
00170 
00172 @property (retain, readonly) UASubscriptionInventory *inventory;
00173 @property (retain, nonatomic) UASubscriptionProduct *pendingProduct;//this should be deprecated
00174 
00178 @property (nonatomic, retain) UASubscriptionDownloadManager *downloadManager;
00179 
00183 
00189 + (UASubscriptionManager*)shared;
00190 - (void)forceRelease;
00191 // ^ The above singleton declarations were inlined for documentation purproses
00192 // from SINGLETON_INTERFACE(UASubscriptionManager)
00193 
00197 
00198 - (Class)uiClass;
00199 + (void)useCustomUI:(Class)customUIClass;
00200 + (void)displaySubscription:(UIViewController *)viewController animated:(BOOL)animated;
00201 + (void)hideSubscription;
00202 + (void)land;
00203 
00215 + (BOOL)setDownloadDirectory:(NSString *)path;
00216 
00229 + (BOOL)setDownloadDirectory:(NSString *)path withProductIDSubdir:(BOOL)makeSubdir;
00230 
00231 // Public purchase and restore methods
00232 
00236 
00244 - (void)purchase:(UASubscriptionProduct *)product;
00245 
00253 - (void)purchaseProductWithId:(NSString *)productId;
00254 
00255 // The following methods (pending subs) should be deprecated
00256 - (void)setPendingSubscription:(UASubscriptionProduct *)product;
00257 - (void)purchasePendingSubscription;
00258 
00271 - (void)restoreAutorenewables;
00272 
00279 - (void)loadSubscription;
00280 
00281 // Private
00282 @property (retain, readonly) UASubscriptionObserver *transactionObserver;
00283 
00284 // Private observer notifiers - do not use
00285 - (void)enterForeground;
00286 - (void)enterBackground;
00287 - (void)subscriptionWillEnterForeground;
00288 - (void)subscriptionWillEnterBackground;
00289 - (void)subscriptionsUpdated:(NSArray *)subscriptions;
00290 - (void)userSubscriptionsUpdated:(NSArray *)userSubscritions;
00291 - (void)inventoryUpdateFailedWithError:(NSError *)error;
00292 - (void)purchaseProductFinished:(UASubscriptionProduct *)product;
00293 - (void)purchaseProductFailed:(UASubscriptionProduct *)product withError:(NSError *)error;
00294 - (void)downloadContentFinished:(UASubscriptionContent *)content;
00295 - (void)downloadContentFailed:(UASubscriptionContent *)content;
00296 - (void)restoreAutorenewablesFinished:(NSArray *)productsRestored;
00297 - (void)restoreAutorenewableProductFailed:(UASubscriptionProduct *)product;
00298 - (void)restoreAutorenewablesFailedWithError:(NSError *)error;
00299 
00300 @end
 All Classes Functions Variables Properties