Getting started with iOS 6 Passbook 1/2

Source: Internet
Author: User


Passbook is one of the hottest iOS 6 technologies released by Apple. It brings more ground-breaking than we can imagine.

Passbook is a great combination. The combination of the four independent technologies brings a brand new experience to iPhone users:

  1. New iOS frameworkPassKit
  2. Brand newPassbookApplication, bound to and released with iOS
  3. Apple'sPush notificationService (this time it will ensure the sending is successful)
  4. Your ownServer code!

    Passbook is very different from other Apple technologies you have used. What makes him different is the concept of a file format. You can create a Passbook file and present it to the user in the desired way. What technology and programming language does it depend on you!

    Without a doubt, with this setup, you can have more control over what you implement than other Apple technologies.

    Because Apple does not have a backend mechanism for processing Passbook, you need to use a series of different technologies to implement it. In this tutorial, you will use Objective-C and iOS, use JSON, send multiple emails with attachments, and use OpenSSL to digitally sign files.

    This tutorial is divided into two parts:

    1. First, you will learn how to manually create a Passbook file. Starting from an empty file, you will eventually complete a completely stylized and digitally signed Passbook file.
    2. Then, you will develop a small iOS app to preview Passbook on the iPhone simulator or your device. You will also learn about different types of Passbook files and then become a Passbook expert.

      This chapter looks messy, but it is very helpful-after reading it, you will be proficient in Apple's latest technology!

      Part 1: Understanding and creating the Passbook file Passbook is everything in your pocket

      Apple's introduction to Passbook says "everything in your pocket ". I like this sentence very much because it demonstrates how you can and should create your applications and services creatively. Passbook can be anything.

      "But what are they?You may ask this question.

      Well, this is what Passbook looks like on the iPhone:

      You can easily recognize several different elements on the Pass. They give you some important information: a logo and company name are at the top,"Free hug!This Pass is clearly described, and there is information about its availability (start time, duration ).

      Then there is a bar code at the bottom. It is very similar to the bar code you see on train tickets, plane tickets, and shopping vouchers. If you think about it carefully, the Pass in your iPhone can save the same information as the paper tickets filled with your pockets, right? Some text, a bar code-that's all. Believe me, the digital coupons on your iPhone can do more.

      What is a Pass?

      Let's take a look at what the pass has and think about the different parts it has:


      All types of pass have these important things:

      1. Top headThe top bar contains an easily identifiable Logo and a company name. The header area is displayed in the Passbook list. It contains the most critical information you want to provide to users, so that they can identify the pass they need.
      2. Subject Region. This part contains the pass content. Each pass has different styles in this region. It usually displays the most important information when the pass is opened. For example, "20% off", "a free cup of coffee", "$120 off", or other such information is very useful.
      3. Additional informationThe third part is used as additional information-it is still very important information (the validity and start time of the promotion in the example), but it is definitely not as important as the information about what pass is.
      4. Bar Code. The barcode contains the encoded information, which can be easily transferred to other systems through the barcode scanner. In the preceding example, the barcode contains an encryption code. After the file is decoded by the scanner section, it will give the pass owner a free hug (send now ).

        Now, you may think about the paper tickets and Shopping vouchers. The things you use every day can be converted to the iPhone.

        Do I board with this pass, or do I get a free coffee?

        Before writing any code, let's take a look at different types of pass.

        Apple defines four different pass types, each of which is commonly used, and there are also 5th, which are used for "universal" purposes. Why are there so many different passes? How do you identify them?

        Predefined pass types are used to display different types of information for different purposes. This is why the layout and content of your gym membership card are different from those of your concert tickets! The former requires your photo, while the latter does not.

        Layout is the main way to distinguish these different types of pass, but some UI features, such as rounded corners, paper-cutting can also easily identify the pass. These differences are small, but obvious, which is why you need to ensure that the correct pass type is used.

        Here are four predefined pass types:

        • Discount
        • Boarding pass
        • Shopping coupons
        • Activity tickets

          However, there is still a pass of the common type. The second part of the tutorial discusses all these five types.

          Now, let's take a look at the boarding pass below the plane. You will see that he is very similar to the previous hug coupon, but there are some key differences: it provides two columns of layout, so that you can easily find the cities to leave and arrive; when you leave the station number, the event and seat number are also neatly arranged.

          Now, I'm sure you have been convinced that pass is a great thing on the iPhone! Let's see how pass is set and how to create one!

          Internal Structure of pass

          This section describes the components of pass. Pass is displayed to users through a file with the extension. pkpass. ("Pkpass" means PassKit Pass-well understood, right ?)

          . PkpassIt is just a. zip file. If you rename it as ZIP and decompress it, you will find some files. Here is the Free Hug Pass content you saw earlier:

          • Pass. json-Description of the pass information area, their content, and metadata.
          • Manifest. json-This file describes the file list in this pass and the SHA1 checksum of each file.
          • Signature-Manifest. json: A separate DER signature generated using the certificate provided by Apple.
          • Background.png-The image displayed on the front of pass.
          • Background@2x.png-The size of the Retina screen is displayed on the front of pass.
          • Logo.png-The logo displayed in the pass header area. Apple recommends a solid color and monochrome logo. The size of the image is determined by you, but the height cannot exceed 50px to fit the height of the head.
          • Logo@2x.png-Logo image of the Retina screen
          • Icon.png-A small icon of pass, which is used as an email attachment. At the time of writing this tutorial, there is no document on the image size, but it looks like 29x29 pixels (the large size icon will be scaled, so their display effect is also good ).
          • Icon@2x.png-Retina version icons
          • Strip.pngAndStrip@2x.png-Use the background of the primary entry. It is only used for discount coupons and Shopping vouchers.

            That's all!

            As you can see, the main file of pass isPass. jsonThis JSON file. In it, you declare all the information on the front and back of the pass. You provide all the pictures to be displayed for this pass (in the case of coupons, you must specify background.png and its retina version ). In the end, you need a configuration file that contains the SHA1 checksum and a separate signature for all these files, so that Passbook can verify that the pass has not been modified after you create it.

            Let's write some JSON!

            Now you can write some code. Let's see if you can recreate a Free Hug pass!

            Wait! JSON is not Objective-C. It is not even any programming language. It is just a markup language used to describe the data structure. So, how do you write JSON? In fact, you can use any text editor-Xcode, TextMate, Coda or TextEdit. In this chapter, you will use Xcode.

            In the Xcode menu, select File/New/File... Then, select iOS/Other/Empty as the file type. Name the new filePass. jsonAnd save it to the directory you selected. Note that you may want to create a new directory to store pass, because you will store a lot of pass-related files in the same directory. It is a good choice to put them together.

            Now you should be able to see this blank window, just like this:

            But there's no problem.-Don't worry!

            You can understand

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.