Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

IAP framework!

License

NotificationsYou must be signed in to change notification settings

wilddylan/APKit

Repository files navigation

##APKit

MIT LicenceFOSSA Status

How to use

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;}

handleProductRequestNotificationwill 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];

sendreceiptStrto your server.

About local receipt verifylocal verify your receipt.

or usego-iap-verify-receipt

Release note
  • 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.

ReadMe in cdn

APKit introduction

License

MIT.

FOSSA Status

About

IAP framework!

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp