- Notifications
You must be signed in to change notification settings - Fork25
wilddylan/APKit
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
##APKit
The under code block only for OS X:
if ( ![NSDatadataWithContentsOfURL:[NSBundlemainBundle].appStoreReceiptURL] ) {exit(173);}
Can be used in Objective-C or swift:
pod'APKit','~> 0.3.1'
run commandpod update --no-repo-update
.
InAppDelegate.m
:
#import<StoreKit/StoreKit.h>#import<APKit/APKit.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {#warning Add transaction observer [[SKPaymentQueuedefaultQueue]addTransactionObserver:[APStoreObserversharedInstance]];returnYES;}
- (void)applicationWillTerminate:(UIApplication *)application {#warning Remove transaction observer [[SKPaymentQueuedefaultQueue]removeTransactionObserver: [APStoreObserversharedInstance]];}
Set result listener:
- (instancetype)init { self = [superinit];if ( self ) { [[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(handleProductRequestNotification:)name:APProductRequestNotificationobject:[APProductManagersharedInstance]]; [[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(handlePurchasesNotification:)name:APPurchaseNotificationobject:[APStoreObserversharedInstance]]; }return self;}
handleProductRequestNotification
will be fired when get response for product.
handlePurchasesNotification
will be fired when get response for purchase.
Request product with identifier:
- (void)viewDidLoad { [superviewDidLoad];NSArray *productIdentifiers = @[@"1994101101",@"1994101102",@"1994101103" ]; APProductManager *productManager = [APProductManagersharedInstance]; [productManagerfetchProductInformationForIds:productIdentifiers];}
-(void)handleProductRequestNotification: (NSNotification *)notification { APProductManager *productRequestNotification = (APProductManager*)notification.object; APProductRequestStatus result = (APProductRequestStatus)productRequestNotification.status;if (result == APProductRequestSuccess) {NSLog(@"VALID:%@", productRequestNotification.availableProducts);NSLog(@"INVALID:%@", productRequestNotification.invalidProductIds); }}
1994101103 is an invalid product identifier.
Purchase:
NSArray *productArray = productRequestNotification.availableProducts;if ( productArray.count >0 ) { SKProduct *product_1 = productArray.firstObject; APStoreObserver *storeObs = [APStoreObserversharedInstance]; [storeObsbuy:product_1];}
#pragma mark - Handle purchase notification-(void)handlePurchasesNotification: (NSNotification *)notification { APStoreObserver *purchasesNotification = (APStoreObserver *)notification.object; APPurchaseStatus status = (APPurchaseStatus)purchasesNotification.status;switch ( status ) {#pragma - Purchasecase APPurchaseSucceeded: {NSLog(@"Purchase-Success:%@", purchasesNotification.productsPurchased);// Verify receipts step. [selfverifyReceipts];break; }case APPurchaseFailed: {NSLog(@"Purchase-Failed%@", purchasesNotification.errorMessage);break; }case APPurchaseCancelled: {NSLog(@"Purchase-Cancelled!");break; }#pragma - Restorecase APRestoredSucceeded: {NSLog(@"Restored-Success:%@", purchasesNotification.productsRestored);break; }case APRestoredFailed: {NSLog(@"Restored-Failed%@", purchasesNotification.errorMessage);break; }case APRestoredCancelled: {NSLog(@"Restored-Cancelled!");break; }default:break; }}
Watch for line 12, [self verifyReceipts];
it's important.
Verify receipt:
If you get some error, try to useSKReceiptRefreshRequest。
NSURL *localReceiptURL = [[NSBundlemainBundle]appStoreReceiptURL];NSData *data = [NSDatadataWithContentsOfURL:localReceiptURL];NSString *receiptStr = [database64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
sendreceiptStr
to your server.
About local receipt verifylocal verify your receipt.
or usego-iap-verify-receipt
0.3.2: Update comments and add some documents, update license, remove unused files and folders.
0.3.0, 0.3.1: Clean workspace, format code with 2 indent.
0.2.0: Download Hosted content.
0.1.0: basic features develope, initialized repo.
MIT.