Coder Social home page Coder Social logo

iapmanager's Introduction

IAPManager

Yet Another simple in-app purchase interface for iOS.

A simple toolkit for non-renewables (a.k.a "Premium Features") with In-App Purchase. The main goal is ease of use. Therefore, more complicated parts, like checking of receipts, are not provided.

Features

  • Simple setup
  • Efficient one-line check if a product was purchased
  • SKProducts to obtain prices
  • Restoring purchases
  • Uses block for callbacks

Requirements

iOS 5 or above with ARC and StoreKit.framework.

How-to

  1. Create your purchases in iTunes Connect. For details see the In-App Purchase Programming Guide.
  2. Add StoreKit.framework to your project
  3. Add IAPManager.h and IAPManager.m into your project, or use the Pod IAPManager.
  4. Create your IAP UI
  5. Use the methods of the [IAPManager sharedIAPManager] singleton:
    • Check if the App Store is available: [[IAPManager sharedIAPManager] canPurchase]
    • To obtain product information:
[[IAPManager sharedIAPManager] getProductsForIds:@[@"superpremiumversion"]
                                      completion:^(NSArray *products) {
                                          BOOL hasProducts = [products count] != 0;
                                          if(! hasProducts) {
                                              NSLog(@":(");
                                          }
                                          else {
                                              SKProduct *premium = products[0];
                                          
                                              NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];                                                                                                                 [numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
                                              [numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
                                              [numberFormatter setLocale:premium.priceLocale];
                                              NSString *formattedPrice = [numberFormatter stringFromNumber:premium.price];
                                              NSLog(@"super premium: %@ for %@", premium.localizedTitle, formattedPrice);
                                          }
}];
- To purchase a product:
[[IAPManager sharedIAPManager] purchaseProductForId:@"superpremiumversion"
                                         completion:^(SKPaymentTransaction *transaction) {
                                             [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
                                             UIAlertView *thanks = [[UIAlertView alloc] initWithTitle:@"Thanks!"
                                                                                              message:@"The extra features are now available"
                                                                                             delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                                             [thanks show];
                                         } error:^(NSError *err) {
                                             [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
                                         
                                             NSLog(@"An error occured while purchasing: %@", err.localizedDescription);
                                             // show an error alert to the user.
                                         }];
  StoreKit will then ask the user if they want to purchase the product.

Contact

Travis CI build status FOSSA Status

Bug reports and pull requests are welcome! Contact me via e-mail or just by opening an issue on GitHub.

License

FOSSA Status

iapmanager's People

Contributors

fossabot avatar hakanw avatar iamamused avatar igmcdowell avatar mruegenberg avatar olejnjak avatar peyoo avatar phpmaple avatar siuying avatar stefanmunz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

iapmanager's Issues

Error handling

If you have no connection the product lookup will fail but will never return an error.

Need to implement

  • (void)request:(SKRequest *)request didFailWithError:(NSError *)error;

Crashing when restoring purchases with error handler.

When I used
[[IAPManager sharedIAPManager] restorePurchasesWithCompletion:^{
NSLog(@"%@", @"Restore Purchases Completion");
} error:^(NSError *error) {
NSLog(@"Restore Purchases Error %@",error.localizedFailureReason);
}];
crash ,more information output by Xcode

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[IAPManager restorePurchasesWithCompletion:error:]: unrecognized selector sent to instance 0x146ea4b0'
*** First throw call stack:
(0x30285fd3 0x3aa32ccf 0x30289967 0x30288253 0x301d77f8 0xee07d 0x32ad7057 0x32ad6ff7 0x32ad6fd1 0x32ac2737 0x32ad6a4f 0x32ad6721 0x32ad16eb 0x32aa68ed 0x32aa4f97 0x3025125b 0x3025072b 0x3024ef1f 0x301b9f4f 0x301b9d33 0x350be663 0x32b0516d 0xed539 0x3af3fab7)
libc++abi.dylib: terminating with uncaught exception of type NSException

when I used
[[IAPManager sharedIAPManager] restorePurchasesWithCompletion:^{
NSLog(@"%@", @"RestorePurchases");
}
Everything goes well.

Perhaps caused SIMULATE_PURCHASES condition.
But I don't know anything with other conditions, as I'm fresh man

No hook for handling errors on restore purchases.

Purchasing takes a completion and error block, but restoring purchases only takes a completion block (no error). This means there's no way to gracefully handle exceptions on a restore purchase action with this library.

I'm working on a patch, will submit shortly.

Update persistence for iOS 7

When using iOS 7, there is a new process for persisting purchased non-consumable IAPs. See here:
"For non-consumable products and auto-renewable subscriptions in iOS 7 and later, use the app receipt as your persistent record."

canPurchase

The documentation says to use "canpurchase" first and then get the products.
I am currently wondering what "canpurchase" is actually checking. If i disable my internet connection, "canpurchase" still returns "YES".

So it should be my job to check for internet connection, then call "canpurchase"?

Handling Restore calls without having purchases anything

If a user restores and hasn't purchased anything before IAPManager calls
the restoreCompletionBlock. Which I think is the wrong UX

This case is not handled by -(void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
because "error" is a transaction error to the Apple servers, but not
a empty SKPaymentQueue (as I thought before. lol)

A modified - (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
fixes it.

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {

    if (!queue.transactions || [queue.transactions count] == 0) {
        if(self.restoreErrorBlock) {

            self.restoreErrorBlock(0);
        }


    } else if (self.restoreCompletionBlock) {
            self.restoreCompletionBlock();
        }


    self.restoreCompletionBlock = nil;
    self.restoreErrorBlock = nil;
}

Already downloaded - cannot purchase

Somewhat randomly, I'm seeing "Already downloaded, cannot purchase" for in app purchases, and hasPurchased is returning false.

The net effect of this is that I have customers who have purchased IAP who cannot access the IAP. Why could this be happening? Is there something I can do on my end to address this?

canMakePayments doesn't check for connectivity (as staten in readme)

the canMakePayments method does not check if the appstore is available but as mentioned in the SKPaymentQueue docs "Returns whether the user is allowed to make payments.", means if he is unter parental restriction or something like this.

Either alter the docs to reflect the functionality or (which would be awesome;) ) add connectivity checking functionality.

great framework btw! super easy to use

possible easy connectivity check:

#include<unistd.h>
#include<netdb.h>

+(bool)connectionAvailable{
    const char *hostname = "appstore.com";
    struct hostent *hostinfo;
    hostinfo = gethostbyname (hostname);
    if (hostinfo == NULL){
#ifdef DEBUG
        NSLog(@"-> no connection!\n");
#endif
        return NO;
    }
    else{
#ifdef DEBUG
        NSLog(@"-> connection established!\n");
#endif
        return YES;
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.