MKStoreKit 4.0 for Auto-renewal subscriptions

2k Views Asked by At

The app is such that all content can be accessed only once a user has subscribed to a scheme (1 month, 3 months, 6 months or a year). So initially when the app is first installed a view with options to buy these schemes appears. Once a user selects a scheme and makes a purchase he is given access.

I initialize the delegate at application: didFinishLaunchingWithOptions: In the first ViewController I listen for the kProductFetchedNotification notification. and once I receive all the products i populate the interface. I also check if a subscription is active

- (void)viewDidLoad {
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(productFetchSuccesful:) name:kProductFetchedNotification object:nil];
    ...

    if([[MKStoreManager sharedManager] isSubscriptionActive:kFeatureAId]){

        [self grantAccess];
    }else if([[MKStoreManager sharedManager] isSubscriptionActive:kFeatureBId]){
    ...
    ...
}


-(void)productFetchSuccesful:(NSNotification*)notification{

    NSArray *products = (NSArray*)[[MKStoreManager sharedManager] purchasableObjectsDescription];
    NSLog(@"%@",products);
    //*****populate ui
}

Once the interface is populated. The UIbuttons associated with each subscription scheme is linked to an IBAction

-(IBAction)purchaseSubscription:(id)sender{
    UIButton *currentBtn = (UIButton*)sender;
    switch (currrentBtn.tag) {
        case product1Tag:
            [[MKStoreManager sharedManager] buyFeature:kFeatureAId
                                            onComplete:^(NSString* purchasedFeature)
             {
                 NSLog(@"Purchased: %@", purchasedFeature);

                 [self grantAccess];
             }
                                           onCancelled:^
             {

             }];
            break;
        case product2Tag:
            ...
            ...
            ...
    }
}

I have set the values in the MKStoreKitConfigs.h have set OWN_SERVER and shared secret

#define kConsumableBaseFeatureId @"com.mycompany.myapp."
#define kFeatureAId @"1month"
#define kFeatureBId @"7days"
#define kConsumableFeatureBId @"com.mycompany.myapp.005"
#define FishBasket @"FishBasket"

#define SERVER_PRODUCT_MODEL 1
#define OWN_SERVER @"http://testsite.com/demo/itunes"
#define REVIEW_ALLOWED 1

//#warning Shared Secret Missing Ignore this warning if you don't use auto-renewable subscriptions
#define kSharedSecret @"*****"

I have put up the server side codes as well but it doesn't seem to be working. Nothing seems to be recorded in the database as well.

How do I get this right?

1

There are 1 best solutions below

1
On

Auto-renewable subscriptions don't require server components. Apple automatically takes care of remembering subscriptions on the server.