IOS development-passbook details and development cases

Source: Internet
Author: User

Passbook is a new feature of iOS 6 and can only be used on iPhone and iPod Touch devices. It helps us manage e-membership cards, credit card points, and coupons issued by sellers. This will have a profound impact on the future of e-commerce. Sellers can improve interaction with consumers by issuing membership cards, credit card points, and coupons to attract more consumers. The birth of passbook is precisely to save all these cards and coupons electronically in the iPhone or iPod Touch.

 

Passbook and pass

The passbook in iOS 6 helps us to centrally manage electronic "cards" and "coupons". These electronic "cards" and "coupons" are "pass" and "Passbook" Are these "Pass collection management applications. The relationship between passbook and pass. passbook is our "card package", while pass is the "card" and "coupon" in it ".

When we select one of the cards, the cards will slide out and click the "I" button in the lower right corner to flip to the back. You can click the recycle bin button in the upper left corner to delete it. A confirmation box with a metallic paper shredder style is displayed. When you click the delete button, the Shredder will smash the card, there are also animation effects. I was amazed every time I used this function, and Apple was impeccable in designing the details.

5 pass styles

IOS 6 currently provides five types of Pass, which are:

Boarding passes (boarding pass ). Although literally translated as "boarding pass", it includes boarding pass, train ticket, boarding pass, and other types of tickets. There are information such as the starting and ending points, time and boarding pass on the pass.

Coupons (coupon ). Or a discount card is used to describe the electronic creden。 of the product's discount or discount information. Generally, there will be a seller's logo, discount ratio, term of use, and other information.

Store cards (shopping card ). This section describes the electronic credential of your account balance in a mall or club. Generally, there will be user-level information.

Event tickets (Admission Ticket ). Describes electronic creden for admission tickets such as sports competitions, concerts, and concerts. Generally, there will be a large background image. The image is blurred and can be scaled down clearly.

Generic ). If the above four types cannot meet the requirements, we can use this type, which can be used to customize the above content. A general card membership card.

Internal Structure of pass

Each pass is a compressed file in ZIP format. The file suffix is pkpass, which is used by users in some special ways. We will introduce these special methods later. If we open the pkpass file using the decompression software, we will see the following content:

Pass

── Icon.png

── Icon@2x.png

── Logo.png

── Logo@2x.png

── Thumbnail.png

── Thumbnail@2x.png

── Background.png

── Background@2x.png

── Strip.png

── Strip@2x.png

── Manifest. JSON

├ ── Fr. lproj

│ └ ── Pass. Strings

── De. lproj

│ └ ── Pass. Strings

── Pass. JSON

── Signature

The pass. JSON file is the core of the pass. It describes all the information on the front and back of the pass. We provide all the images to be displayed for this pass. Finally, a configuration file manifest is required. JSON, which contains the sha1 checksum of all these files and a separate signature file signature, so that passbook can verify that this pass has not been modified after it is created.

Pass kit programming: Example: mypass instance design and description

Next, we will introduce the programming process of the pass kit through an instance (mypass), and design the prototype sketch of the mypass instance. When mypass is started, the home page is a table view screen. It queries some specific passes in the passbook on the local device and then displays the table view screen. Click the "+" button. If the boarding pass exists, replace it. Otherwise, add the boarding pass to passbook. the boarding pass is requested to be downloaded from the iosbook3.com server. If you click a cell in the table view, the screen will jump to the Pass Details screen. In the Details screen, you can click the "Remove" button in the upper-right corner of the navigation bar to delete the current pass from passbook.

Start passbook

1. Create an app ID

If any iOS app requires an app ID, enter "Pass kit Dev" in the description project and select "use team ID" in the bundle seed ID (app id prefix) project ". In the bundle identifier (app id suffix) project, enter "com.51work6. mypass ".

After successful creation, the app ID page is displayed. In the app ID list, you will find the pass kit Dev

2. Configure pass availability

By default, the created application cannot access passbook. You need to click the configure hyperlink to go to the application configuration page and select enable for passes to enable pass.

Click the "done" button in the lower right corner of the configuration to save the configuration and return to the app ID list page. At this time, let's take a look at the application We Just configured, its pass status changes to green available.

3. Create a configuration Profile

To be able to write applications on devices, we also need to create a configuration profile. After the configuration is created, download the configuration summary file to your local device.

4. Create a pass type ID

Creating a pass type ID is also an important step. We need to set the pass type ID to "pass.com. 51work6. Boarding-pass ".

5. Configure the xcode project code signature

After completing the preceding work, we need to create and configure the xcode project, create the project name "mypass" application, and then configure the xcode project code signature. This signature requires 3rd steps to create a configuration profile.

Select tagets → mypass → code signing identity, and then select pass kit Dev profile.

After setting, you can start encoding.

6. Configure xcode project configuration authorization information

The configuration authorization information is similar to that of the iCloud application. Select tagets → mypass → summary → entitlements. Here we can configure the authorization information.

The authorization information items are described as follows:

Entitlements: Check use entitlements file to specify an authorization file. This file is not created by yourself in your project directory. It records the detailed authorization configuration information below;

Pass: select the pass type identifier. First select use selected pass type identifier, and then select pass.com. 51work6. Boarding-pass;

So far, the preliminary preparation process of programming has been completed. Next we will introduce the programming process of the instance.

Access passbook

The pass operation is completed through the pkpasslibrary class. The pkpasslibrary class is not designed as a singleton. Use the following code to obtain the instance object:

Pkpasslibrary * passlib = [[pkpasslibrary alloc] init];

Methods related to accessing passbook in the pkpasslibrary class include:

Passes obtains the pass specified by all authorization files in passbook. The pass type ID specified in the authorization file is pass.com. 51work6. boarding-pass, so this method obtains the pass type ID as pass.com. 51work6. all boarding-Pass pass.

Passwithpasstypeidentifier: serialnumber: gets the pass object through the specified pass type ID and serial number.

Next let's look at the relevant program code. The viewcontroller. H code is as follows:

#import <UIKit/UIKit.h>#import ”ASIHTTPRequest.h”#import ”PassKit/PassKit.h”#import ”DetailViewController.h”#define SerialNumber @”gT6zrHkaW”@interface ViewController :UITableViewController <PKAddPassesViewControllerDelegate>@property (strong, nonatomic) NSArray* passes;- (IBAction)add:(id)sender;@end

 

The viewcontroller. m code is as follows:

-(Void) viewdidload {[Super viewdidload]; // determine whether passbook is available if (! [Pkpasslibrary ispasslibraryavailable]) {nslog (@ "passbook unavailable .");} Else {[[nsicationcenter center defacenter center] addobserver: selfselector: @ selector (handler :) name: jsonobject: Nil] ;}}-(void) viewwillappear :( bool) animated {[Super viewwillappear: yes]; // refresh the screen [self handlelibrarychange: Nil];} # pragma mark-notification for handling passbook changes-(void) handlelibrarychange :( nsnotification *) not ④ {pkpasslibrary * passlib = [[pkpasslibrary alloc] init]; // sort nssortdescriptor * byname = [nssortdescriptorsortdescriptorwithkey: @ "localizedname" ascending: Yes]; _ passes = [[passlib passes] sortedarrayusingdescriptors: @ [byname]; [self. tableview reloaddata];}-(void) didreceivememorywarning {[Super didreceivemorywarning]; [[nsicationicationcenter defacenter center] removeallobjects];}

 

Release pass

After the pass signature and compression are successful, how can I publish the pkpass file to users? For pkpass files provided to common users, there are three release methods: email release, web site release, and in-app release.

Email Publishing

This release method is to send the pkpass file as an email attachment to the user. It is recommended that the user open the email address on his iPhone or iPod Touch device to read the email. The passage in the emailattachment. The graph in the attachment is the logo.png file in the passage.

When you click the attachment "store card", the page will jump to and click "add" on the right of the navigation bar to add the pass to passbook.

If you do not receive an email on your iPhone or iPod touch, you can use the email application to receive the email on Mac OS X 10.8.2 or later.

Click "view creden……" in the email ..." Button to pop up the Add pass dialog box.

If this pass is not added to passbook, the button in the lower-right corner is "add to passbook". If it has been added to passbook, the button is "completed" or "updated ".

Passbook is here! For more information about passbook, refer to my new book "iOS network programming and cloud application best practices" and the "Apple e-commerce discussion-ios6 passbook Analysis and Development" open classes for dobe free in November May 30.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.