SDK

Implementation

With the Notificare's Monetize add-on you can easily sell virtual goods in the App Store. Our library will provide you all the mechanisms to quickly develop an engaging in-app store experience where you can sell digital products.

Please note that be able to complete a transaction while using sandbox servers, you will need to create test users with access to your app in Apple’s Developer Portal. Your can find more information about test users here.

In your AppDelegate.m or AppDelegate.swift add the following delegate:

- (void)notificarePushLib:(NotificarePushLib *)library didLoadStore:(NSArray *)products{
    //Store is ready
}
func notificarePushLib(_ library: NotificarePushLib, didLoadStore products: [Any]) {
    //Store is ready
}

If your products have been loaded successfully this delegate will be triggered. This will mean it is safe for your app to show the UI for your store.

If there is some issue with your products or your account, the following delegate is triggered instead:

- (void)notificarePushLib:(NotificarePushLib *)library didFailToLoadStore:(NSError *)error{
    //Store failed to load, hide UI?
}
func notificarePushLib(_ library: NotificarePushLib) throws {
    //Store failed to load, hide UI?
}

If your store is loaded successfully, then you can display your products, to retrieve the list of products invoke the following method:

[[NotificarePushLib shared] fetchProducts:^(NSArray *info) {
    //Handle the list of NotificareProduct objects
} errorHandler:^(NSError *error) {
    //Handle error
}];
NotificarePushLib.shared().fetchProducts({(_ info: [Any]) -> Void in
    //Handle the list of NotificareProduct objects
}, errorHandler: {(_ error: Error?) -> Void in
    //Handle error
})

You can also retrieve a list of the purchased products, this can be used to allow or not products to be bought again (depending on their type) or automatically give access to the content they unlock. To do that, simply invoke the following method:

[[NotificarePushLib shared] fetchPurchasedProducts:^(NSArray *info) {
    //Handle the list of NotificareProduct objects
} errorHandler:^(NSError *error) {
    //Handle error
}];
NotificarePushLib.shared().fetchPurchasedProducts({(_ info: [Any]) -> Void in
    //Handle the list of NotificareProduct objects
}, errorHandler: {(_ error: Error?) -> Void in
    //Handle error
})

To get a specific product using its identifier, invoke the following method:

[[NotificarePushLib shared] fetchProduct:"MY_PROD_IDENTIFIER" completionHandler:^(NotificareProduct *product) {
    //Handle success
} errorHandler:^(NSError *error) {
    //Handle error
}];
NotificarePushLib.shared().fetchProduct("MY_PROD_IDENTIFIER", completionHandler: {(_ product: NotificareProduct) -> Void in
    //Handle success
}, errorHandler: {(_ error: Error?) -> Void in
    //Handle error
})

Finally to allow a user to buy a product, simply invoke this method.

[[NotificarePushLib shared] buyProduct:(NotificareProduct*)prod];
NotificarePushLib.shared().buy((prod as? NotificareProduct))

Handle Downloads

You can eventually use the methods below to handle your Non-Consumable's hosted content (if applicable). The accepted parameter should be an array of SKDownload objects.

To pause one or more downloads, invoke the following method:

[[NotificarePushLib shared] pauseDownloads:downloads];
NotificarePushLib.shared().pauseDownloads(downloads)

To resume downloading one or more downloads, invoke the following method:

[[NotificarePushLib shared] resumeDownloads:downloads];
NotificarePushLib.shared().resumeDownloads(downloads)

To cancel one or more downloads, invoke the following method:

[[NotificarePushLib shared] cancelDownloads:downloads];
NotificarePushLib.shared().cancelDownloads(downloads)

Finally when a download is completed, you can access the hosted content by invoking the following methods:

NSString * dir = [[NotificarePushLib shared] contentPathForProduct:[product identifier]];
NSError * error;
NSArray * directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:dir error:&error];
var dir: String = NotificarePushLib.shared().contentPath(forProduct: product.identifier())
var error: Error?
var directoryContents = try? FileManager.default.contentsOfDirectory(atPath: dir)

In-App Purchase Delegates

The method above will start the purchase flow handled by iOS and the App Store. You can then use the following delegates to understand the state of the purchase or the hosted content associated to the product. Use should use them to update UI or show errors.

- (void)notificarePushLib:(NotificarePushLib *)library didFailProductTransaction:(SKPaymentTransaction *)transaction withError:(NSError *)error{
    //Triggered when purchase did not finish or failed
}

- (void)notificarePushLib:(NotificarePushLib *)library didCompleteProductTransaction:(SKPaymentTransaction *)transaction{
    //Triggered when purchase is completed
}

- (void)notificarePushLib:(NotificarePushLib *)library didRestoreProductTransaction:(SKPaymentTransaction *)transaction{
    //Triggered when your try to buy a product that is already bought
}

- (void)notificarePushLib:(NotificarePushLib *)library didStartDownloadContent:(SKPaymentTransaction *)transaction{
    //Triggered when it starts downloading hosted content
}

- (void)notificarePushLib:(NotificarePushLib *)library didPauseDownloadContent:(SKDownload *)download{
    //Triggered when a download is paused
}

- (void)notificarePushLib:(NotificarePushLib *)library didCancelDownloadContent:(SKDownload *)download{
    //Triggered when a download is cancelled
}

- (void)notificarePushLib:(NotificarePushLib *)library didReceiveProgressDownloadContent:(SKDownload *)download{
    //Triggered while a download is in progress
    NSLog(@"didReceiveProgressDownloadContent %@ %f %f", download, [download progress], [download timeRemaining]);
}

- (void)notificarePushLib:(NotificarePushLib *)library didFailDownloadContent:(SKDownload *)download{
    //Triggered when a download fails
}

- (void)notificarePushLib:(NotificarePushLib *)library didFinishDownloadContent:(SKDownload *)download{
    //Triggered when a download is completed
}
func notificarePushLib(_ library: NotificarePushLib, didFailProductTransaction transaction: SKPaymentTransaction) throws {
    //Triggered when purchase did not finish or failed
}

func notificarePushLib(_ library: NotificarePushLib, didCompleteProductTransaction transaction: SKPaymentTransaction) {
    //Triggered when purchase is completed
}

func notificarePushLib(_ library: NotificarePushLib, didRestoreProductTransaction transaction: SKPaymentTransaction) {
    //Triggered when your try to buy a product that is already bought
}

func notificarePushLib(_ library: NotificarePushLib, didStartDownloadContent transaction: SKPaymentTransaction) {
    //Triggered when it starts downloading hosted content
}

func notificarePushLib(_ library: NotificarePushLib, didPauseDownloadContent download: SKDownload) {
    //Triggered when a download is paused
}

func notificarePushLib(_ library: NotificarePushLib, didCancelDownloadContent download: SKDownload) {
    //Triggered when a download is cancelled
}

func notificarePushLib(_ library: NotificarePushLib, didReceiveProgressDownloadContent download: SKDownload) {
    //Triggered while a download is in progress
    print("didReceiveProgressDownloadContent \(download) \(download.progress) \(download.timeRemaining)")
}

func notificarePushLib(_ library: NotificarePushLib, didFailDownloadContent download: SKDownload) {
    //Triggered when a download fails
}

func notificarePushLib(_ library: NotificarePushLib, didFinishDownloadContent download: SKDownload) {
    //Triggered when a download is completed
}

This is all you need to display, sell and handle hosted content for your in-app products.