Micro.blog

Supporting StoreKit Affiliate ID in iOS 8 w/o breaking iOS 7

Articles, code Comments (0)

As you may already know, iOS 8 finally supports loading a StoreSheet complete with your Affiliate ID. This way you can keep users in your app without sending them over to iTunes or App Store apps and still get commissions from Apple. However if you want to support iOS 7 users (for the time being) you will need to load the Store Kit Product Parameters with the playlist only – or your app will crash. So naturally check for NSFoundationVersionNumber to test for version iOS 7.1 or 8.0 and load the correct parameters.

You can watch the WWDC 2014 Video about this new feature.

Here’s the code using contstants to hold IDs for your playlist, affiliate and campaign IDs.

– (void)openAppStore:(id)sender {

    // Initialize Product View Controller

    SKStoreProductViewController *storeProductViewController = [[SKStoreProductViewControlleralloc] init];

    // Configure View Controller

    [storeProductViewController setDelegate:self];

NSDictionary *parameters;

    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {

        // Load resources for iOS 7.1 or earlier

        parameters = @{SKStoreProductParameterITunesItemIdentifier:kPlaylistID};

    } else {

        // Load resources for iOS 8 or later

        parameters = @{SKStoreProductParameterITunesItemIdentifier:kPlaylistID, SKStoreProductParameterAffiliateToken:kAffiliateID, SKStoreProductParameterCampaignToken:kCampaignID};

    }

[storeProductViewController loadProductWithParameters:parameters completionBlock:^(BOOL result, NSError *error) {

if (error) {

NSLog(@”Error %@ with User Info %@.”, error, [error userInfo]);

} else {

            // Present Store Product View Controller

            [self presentViewController:storeProductViewController animated:YES completion:nil];

}

}];

}

 

Pin It

» Articles, code » Supporting StoreKit Affiliate ID in...
On September 10, 2014
By
, , , , , ,

Leave a Reply

« »