Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A Swift library to parse an IATA 2D Boarding Pass using a string representation of the pass barcode 🎫 🛫

NotificationsYou must be signed in to change notification settings

anomaddev/BoardingPassKit

Repository files navigation

This Swift framework will allow you to parse the barcodes and QR codes of airline boarding passes and other documents that are encoded using the IATA 2D barcode standard.

This Framework is still in development. Please use with caution in your projects!

Installation

Swift Package Manager

Add the package to your Xcode project with the repository URL:https://github.com/anomaddev/BoardingPassKit.git

Example

Here is a simple example using a boarding pass of my own to show how to use the framework.

letbarcodeString="M1ACKERMANN/JUSTIN DAVEJPYKJI SINNRTJL 0712 336Y025C0231 348>3180 O9335BJL 01315361700012900174601118720 JL AA 34DGH32             3"// or you can use a Data representation of the string in .ascii format.letbarcodeData= barcodeString.data(using:.ascii)do{letdecoder=BoardingPassDecoder()    // example of settings you can change on the decoder. This one prints out the data every step of the decoding.    decoder.debug=trueletboardingPass=try decoder.decode(code: barcodeString)letboardingPassFromData=try decoder.decode(data: barcodeData)}catch{    // Handle error}

Boarding Pass

A boarding pass object will contain a few sections. This allows the library to accurately differentiate between mandatory & conditional items in the data.

publicstructBoardingPass:Codable{        /// The IATA BCBP version numberpublicletversion:String        /// The parent object contains the information that is shared between all segments of the boarding pass.publicvarinfo:BoardingPassParent    /// The main segment of the boarding pass.publicvarmain:BoardingPassMainSegment    /// The segments of the boarding pass. This will be empty if there is only one segment.publicvarsegments:[BoardingPassSegment]    /// The Boarding Pass security data used by the airlinepublicvarsecurity:BoardingPassSecurityData        /// The original `String` that was used to create the boarding passpublicvarcode:String}

Boarding Pass Parent

The parent object contains the information that is shared between all segments of the boarding pass. This includes the passenger name, the PNR code, first segments seat number, etc.

publicstructBoardingPassParent:Codable{        /// The format code of the boarding passpublicletformat:String        /// The number of legs included in this boarding passpublicletlegs:Int        /// The passenger's name informationpublicletname:String        /// The electronic ticket indicatorpublicletticketIndicator:String        /// The record locator with the airlinepublicletpnrCode:String        /// The IATA code of the origin airportpublicletorigin:String        /// The IATA code of the destination airportpublicletdestination:String        /// The IATA code of the airline operating the flightpublicletoperatingCarrier:String        /// The flight number of the operating airlinepublicletflightno:String        /// The day of the year the flight takes placepublicletjulianDate:Int        /// The compartment code for the passenger on the main segmentpublicletcompartment:String        /// The seat number for the passenger on the main segmentpublicletseatno:String        /// What number passenger you were to check inpublicletcheckIn:Int        /// Bag check, checked in, etc. This code needs to be parsed.publicletpassengerStatus:String        /// The size of the conditional data in the boarding pass. Parsed decimal from hexidecimal.publicletconditionalSize:Int}

Boarding Pass Main Segment

The main segment contains the information that is unique to the first segment of the boarding pass. This includes the airline code, ticket number, bag tags, etc. There are also fields that specify the size of the conditional items in the data.

publicstructBoardingPassMainSegment:Codable{        /// The size of the main segment in the boarding pass. Parsed decimal from hexidecimal.publicletstructSize:Int    /// The passenger description code.publicletpassengerDesc:String    /// The source of the passenger's check inpublicletcheckInSource:String    /// The source of the passenger's boarding passpublicletpassSource:String    /// The date the boarding pass was issuedpublicletdateIssued:String    /// The type of document the passenger is usingpublicletdocumentType:String    /// The IATA airline code issuing the boarding passpublicletpassIssuer:String        /// Your first bag tagpublicvarbagtag1:String?    /// Your second bag tagpublicvarbagtag2:String?    /// Your third bag tagpublicvarbagtag3:String?        /// The size of the variable data in the boarding pass. Parsed decimal from hexidecimal.publicletnextSize:Int    /// The numeric airline code of the airline issuing the boarding passpublicletairlineCode:String    /// The boarding pass ticket numberpublicletticketNumber:String    /// Selectee indicatorpublicletselectee:String    /// International documentation verification indicatorpublicletinternationalDoc:String    /// Marketing carrierpublicletcarrier:String    /// Frequent flyer carrierpublicvarffCarrier:String?    /// Frequent flyer numberpublicvarffNumber:String?        /// ID/AD indicatorpublicvarIDADIndicator:String?    /// Free baggage allowancepublicvarfreeBags:String?    /// Fast track indicatorpublicvarfastTrack:String?    /// For internal airline usepublicvarairlineUse:String?}

Generating a Barcode or QR Code from Boarding Pass Data

The parser, that deciphers the Boarding Pass string, can also generate a QR Code from the data. This can be useful if you want to display the QR Code on a screen.

QR Code

do{letdecoder=BoardingPassDecoder()letpass=try decoder.decode(data: data)letqrCode=try pass.qrCode()}catch{print(error.localizedDescription)}

PDF417

// Coming Soon

Print to Console

When debugging your functions, you can call theprintout() function on your BoardPass object to print all the details to the console.

/// for this example we will print out the above boarding pass to the consoleboardingPass.printout()//// SEGMENTS: 1// ======================// MAIN SEGMENT// ===MANDATORY ITEMS [60 characters long]===// FORMAT CODE:  M// LEGS ENCODED: 1// PASSENGER:    ACKERMANN/JUSTIN DAV// INDICATOR:    E// PNR CODE:     UXPVFK// ORIGIN:       HKG// DESTINATION:  SIN// CARRIER:      CX// FLIGHT NO:    0715// JULIAN DATE:  326// COMPARTMENT:  Y// SEAT NO:      040G// CHECK IN:     59// STATUS:       3// VAR SIZE:     75// // ===CONDITIONAL ITEMS [75 characters long]===// VERSION:       6// PASS STRUCT:   24// PASS DESC:     0// SOURCE CHK IN:// SOURCE PASS:   O// DATE ISSUED:   9326// DOC TYPE:      B// AIRLINE DESIG: AA// BAG TAG 1:// BAG TAG 2:     none// BAG TAG 3:     none// FIELD SIZE:    42// AIRLINE CODE:  001// TICKET NO:     7459737133// SELECTEE:      0// INTERNATIONAL:// CARRIER:       AA// FREQ CARRIER:  AA// FREQ NUMBER:   76UXK84// // AD ID:// FREE BAGS:// FAST TRACK:    N// AIRLINE USE:   3AA// ======================// // SECURITY DATA// ========================// TYPE:     nil// LENGTH:   nil// DATA:// ========================//

Author

Justin Ackermann

About

A Swift library to parse an IATA 2D Boarding Pass using a string representation of the pass barcode 🎫 🛫

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp