In-app purchasing using Store Kit in Objective-C

Generation QR Code ISO/IEC18004 in Objective-C In-app purchasing using Store Kit

Download from Wow! eBook <www.wowebook.com>
QR Creation In Objective-C
Using Barcode creator for iPhone Control to generate, create QR-Code image in iPhone applications.
www.OnBarcode.com
Barcode Encoder In Objective-C
Using Barcode encoder for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
In-app purchasing using Store Kit
Printing Code 128C In Objective-C
Using Barcode drawer for iPhone Control to generate, create Code 128A image in iPhone applications.
www.OnBarcode.com
QR Code ISO/IEC18004 Maker In Objective-C
Using Barcode encoder for iPhone Control to generate, create Denso QR Bar Code image in iPhone applications.
www.OnBarcode.com
Listing 18.4
Paint Barcode In Objective-C
Using Barcode generation for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
Print Barcode In Objective-C
Using Barcode encoder for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
Delegate methods for UITableView
Creating UPC-A In Objective-C
Using Barcode printer for iPhone Control to generate, create GTIN - 12 image in iPhone applications.
www.OnBarcode.com
Making UPC-E In Objective-C
Using Barcode printer for iPhone Control to generate, create GS1 - 12 image in iPhone applications.
www.OnBarcode.com
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [products count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; } SKProduct * product = [products objectAtIndex:indexPath.row]; cell.textLabel.text = [NSString stringWithFormat:@"$%.2f %@", product.price.doubleValue, product.localizedTitle]; cell.detailTextLabel.text = product.localizedDescription; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; }
Quick Response Code Maker In .NET Framework
Using Barcode generator for ASP.NET Control to generate, create Quick Response Code image in ASP.NET applications.
www.OnBarcode.com
Denso QR Bar Code Reader In Visual Basic .NET
Using Barcode recognizer for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
This code is straightforward: you ve already seen how to populate a UITableView from an NSArray. Note that you populate the cell s text label and detail text label from the localized product information. At this point, you should be able to see your list of products when you run the application. If you intend to test now, make sure you comment out the line to import WallpaperViewController.h, because you haven t yet created it. The next step is to display the wallpapers to the user when they tap on a row in the table. This will allow them to see the wallpaper as well as purchase it. Before you create the view controller you ll use, let s implement the didSelectRowAtIndexPath method of the UITableView to push the new view onto the navigation stack. Listing 18.5 details this code.
Decoding UPC Symbol In VB.NET
Using Barcode recognizer for VS .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
Print Data Matrix 2d Barcode In C#
Using Barcode maker for .NET framework Control to generate, create Data Matrix image in VS .NET applications.
www.OnBarcode.com
Listing 18.5
Paint Code 39 Full ASCII In None
Using Barcode encoder for Font Control to generate, create Code 39 Full ASCII image in Font applications.
www.OnBarcode.com
Code-128 Drawer In Objective-C
Using Barcode generator for iPad Control to generate, create Code 128 Code Set B image in iPad applications.
www.OnBarcode.com
didSelectRowAtIndexPath method for the UITableView
USS-128 Maker In Java
Using Barcode creator for Android Control to generate, create UCC - 12 image in Android applications.
www.OnBarcode.com
Data Matrix 2d Barcode Maker In VS .NET
Using Barcode maker for .NET framework Control to generate, create DataMatrix image in .NET applications.
www.OnBarcode.com
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { SKProduct * product = [products objectAtIndex:indexPath.row]; WallpaperViewController * wpViewController = [[WallpaperViewController alloc] initWithNibName:@"WallpaperViewController" bundle: [NSBundle mainBundle]]; wpViewController.product = product; [self.navigationController pushViewController:wpViewController
GS1 - 13 Maker In None
Using Barcode printer for Online Control to generate, create EAN-13 Supplement 5 image in Online applications.
www.OnBarcode.com
PDF-417 2d Barcode Drawer In Visual Basic .NET
Using Barcode maker for .NET Control to generate, create PDF 417 image in .NET framework applications.
www.OnBarcode.com
Download from Wow! eBook <www.wowebook.com>
Read GS1 - 13 In Visual C#
Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
Barcode Drawer In Java
Using Barcode generation for Android Control to generate, create Barcode image in Android applications.
www.OnBarcode.com
Creating a simple store interface
animated:YES]; [wpViewController release]; }
You first get the product associated with the selected row. This is then passed to the WallpaperViewController class after initialization. The WallpaperViewController uses this product to determine which wallpaper image to display. Finally, the view is pushed onto the navigation view stack. You ll now create the WallpaperViewController. Figure 18.10 shows what its view will look like. To create this object, add a new UIViewController subclass called WallpaperViewController to your project. Make sure you select the With XIB for User Interface check box. Before creating the interface, you need to create the IBOutlets and IBAction. That way, you only have to open Interface Builder once. Open WallpaperViewController.h, and add the code in listing 18.6.
Figure 18.10 Previewing the product in the wallpaper view
Listing 18.6
WallpaperViewController.h
#import <UIKit/UIKit.h> #import <StoreKit/StoreKit.h> @interface WallpaperViewController : UIViewController { IBOutlet UIImageView * imageView; SKProduct * product; } @property (nonatomic, retain) IBOutlet UIImageView * imageView; @property (nonatomic, retain) SKProduct * product; - (IBAction) buttonClicked:(id) sender; @end
As you may have guessed, you only need an IBOutlet for the UIImageView that will display the selected wallpaper. You set its image property from the product property after the view has been initialized. In addition to the IBOutlet, you create an IBAction that responds when the user presses the Purchase button. As you ll see later in this section, this will initiate the inapp purchasing process. After you ve created this header file, open WallpaperViewController.xib in Interface Builder and add a UIImageView and a UIButton. Finally, connect the UIImageView to your IBOutlet and the touchUpInside method of the UIButton to your IBAction.
Download from Wow! eBook <www.wowebook.com>
In-app purchasing using Store Kit
The code for this class is simple. Open WallpaperViewController.m, and implement the methods in listing 18.7.
Listing 18.7 WallpaperViewController.m
#import "WallpaperViewController.h" @implementation WallpaperViewController @synthesize product; @synthesize imageView; - (void)viewDidLoad { Sets image property [super viewDidLoad]; of imageView imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.jpeg",self.product.productIdentifier]]; }
- (IBAction) buttonClicked:(id) sender { SKPayment *payment = [SKPayment paymentWithProductIdentifier: self.product.productIdentifier]; [[SKPaymentQueue defaultQueue] addPayment:payment]; }
You set the image property of the UIImageView to a JPEG with the same name as the product identifier B. To make things easy, you name each of the images you re selling based on their product identifiers. For example, the three images in the sample code are named com.rightsprite.wallpaper.01.jpeg, com.rightsprite.wallpaper.02.jpeg, and com.rightsprite.wallpaper.03.jpeg. If you didn t want to name your images this way, you could store a mapping of product IDs to image names in a plist file. When the user presses the Purchase button, the code creates a new SKPayment object and queue in the global payments queue. Because SKPaymentQueue is a singleton class, payments can be queued from anywhere in your code. All you need is the product identifier of the product being purchased. After the payment has been queued, Store Kit takes over and begins processing it. Figure 18.11 shows the alert that pops up when you press the Purchase button. When the user presses the Buy button, Store Kit notifies your transaction observer class about the status of payment via the delegate methods you declared in listing 18.1. We ll now discuss how to implement those methods and deliver the purchased content to the user. Add the code from listing 18.8 to the file RootViewController.m.
Copyright © OnBarcode.com . All rights reserved.