PassKit on iOS 6

24
PassKit on iOS 6 Craig Dunn

description

Craig Dunn walks us through an introduction of PassKit and how you can take advantage of using this functionality from your MonoTouch applications.

Transcript of PassKit on iOS 6

Page 1: PassKit on iOS 6

PassKit on iOS 6 Craig Dunn

Page 2: PassKit on iOS 6

What is a Pass?

Page 3: PassKit on iOS 6

What is a Pass?

Simple: a Barcode Delivery System“unique number”

Page 4: PassKit on iOS 6

What is a Pass? ii

• 5 Types : Coupon, Generic, StoreCard, BoardingPass, EventTicket

• Barcode (2D formats)

• What’s behind the scenes?

• Barcode

• (hidden) SerialNumber is the unique Idyou can use this to stop duplicates * not same as the barcode data, so you canshow the same barcode to many users

Page 5: PassKit on iOS 6

What is a Pass? iii

• ZIP file

• Pass.json

• Images

{ "passTypeIdentifier":"com.xamarin.passkitdoc.banana", "formatVersion":1, "organizationName":"Xamarin", "serialNumber":"12345436XYZ", "teamIdentifier":"XXXAAA1234", "description":"Xamarin Demo", "foregroundColor":"rgb(54,80,255)", "backgroundColor":"rgb(209,255,247)", "labelColor":"rgb(255,15,15)", "logoText":"Banana ", "barcode":{ "altText":"FREE-BANANA", "format":"PKBarcodeFormatQR", "message":"123456", "messageEncoding":"iso-8859-1" }, /* The following fields are specific to which type of pass. The name of this object specifies the type, e.g., boardingPass below implies this is a boarding pass. Other options include storeCard, generic, coupon, and eventTicket */ "boardingPass":{ /*headerFields, primaryFields, secondaryFields, and auxiliaryFields are arrays of field object. Each field has a key, label, and value*/ "headerFields":[ //Header fields appear next to logoText { "key":"h1-label", //Must be unique. Used by iOS apps to get the data. "label":"H1-label", //Label of the field "value":"H1" //The actual data in the field },

Page 6: PassKit on iOS 6

What is a Pass? iv• Relevance : locations (<10) & datetime (1 only)

• Related App Store apps

• Custom text

• Web Service URL : register/delete/APNS pull updates

(extra bits)

"associatedStoreIdentifiers" : [562123362],

"relevantDate" : "2012-10-17T09:00-05:00", "locations" : [ { "longitude" : -122.3748889, "latitude" : 37.6189722 },{ "longitude" : -122.03118, "latitude" : 37.33182 }],

"backFields" : [ { "key" : "terms", "label" : "TERMS AND CONDITIONS", "value" : "Generico offers this pass......"

"webServiceURL" : "https://example.com/passes/","authenticationToken" : "qwerty123567890asdfpoiuyt",

Page 7: PassKit on iOS 6

Make a Pass

• Must be an “Apple Developer”

• Provisioning Portal : Pass Type ID

• identifier starts with “pass.”

• Requires various root certificates

• signpass app provided by Apple

(manifest & sign)

Page 8: PassKit on iOS 6

Make a Pass ii

• Edit JSON

• Edit images

• (manifest & sign)

• ZIP

https://developer.apple.com/downloads/index.action?name=PassbookApple’s sample (you have to build yourself)

DEMO(?)

Page 9: PassKit on iOS 6

Make a Pass iii

• Watch Console (Xcode)

• Log should tell you whatwent wrong

• HTTP (non-secure) can be usedonly while testing APNS+updates

(testing)

Page 10: PassKit on iOS 6

Your server

images and JSON resourcesused to generate passes

pass & devicedatabase

Passbook

Conduit Apps

Companion Apps

MailSafari

(others)

AppleAPNS servers

Your app

push update notification

request changed

data

webservice

notificationof change

register pass

generate & sign pass

Add Pass

Add Pass

email attachmentsweb links

make changes to passcertificate for signing passes

Scan Pass

Update database Scanner

P.O.S.

sign-pass

Page 11: PassKit on iOS 6

Passbook• Stores & manages Passes

• Renders barcode for scanning(Apple: your app should not perform this function)

• Receives notifications and makes web-service calls

Page 12: PassKit on iOS 6

Conduit Apps

• Summary display and Add

• Mail

• Safari

• <your app>?(probably not)

(Pass pass-thru)

Page 13: PassKit on iOS 6

Companion Apps

• YOUR APP

• Configure App ID in Provisioning Portal

• Generate Provisioning Profiles in Portal(after configuring the App ID)

• Configure app Entitlements.plist

plus Team ID!

Page 14: PassKit on iOS 6

Companion Apps ii

• Access YOUR PassesTeam ID, certificates

• Read from a standard set ofproperties (text, icon)

• Access custom propertiesby JSON “key”

Page 15: PassKit on iOS 6

Companion Apps iii• Companion apps can appear to “generate” Passes

• eg. Starbucks app : adds and updates Passes

• eg. Collect user data (or payment) in your app, then add a Pass

• DO NOT GENERATE PASSES IN APP

• It requires your certificates to sign; they should be kept secure

• Create your own webservice to deliver the Pass file

Page 16: PassKit on iOS 6

Companion Apps iv

• A simple PassKit-capable app

• reads from the Passbook library

https://github.com/xamarin/monotouch-samples/tree/master/PassKitXamarin’s PassKit sample

DEMO #2

Page 17: PassKit on iOS 6

Scanning Apps• YOUR APP or a Point of Sale system or ???

• Only chance to “implement security”(a duplicate Pass is as easy as a screenshot)

• Update server in real-time

• Can trigger APNS > Pass update (eg. store card balance)

Page 18: PassKit on iOS 6

Scanning Apps ii

• Microsoft Azure Mobile Services

• Xamarin Client Library

(MonkeyScan & Azure)

public static readonly MobileServiceClient MobileService = new MobileServiceClient (Constants.AzureUrl, Constants.AzureKey);public static readonly IMobileServiceTable<ConfScan> scanTable = MobileService.GetTable<ConfScan>();

// then...

public TaskScheduler scheduler = TaskScheduler.FromCurrentSynchronizationContext();

// and then...

AzureManager.scanTable.InsertAsync (scan) .ContinueWith (t => { if (t.Status == TaskStatus.RanToCompletion) Console.WriteLine ("Updated scan in cloud " + t.Status + " " + t.Id); else ; // error handling or store and retry... } , scheduler);

MonkeyScan sample https://github.com/conceptdev/MonkeySpace/tree/master/iOS.MonkeyScan

Page 19: PassKit on iOS 6

Scanning Apps iv

• MonkeySpace attendeesare on-time!

• App has real-time count

(MonkeyScan)

Page 20: PassKit on iOS 6

Updates with APNS

Your server

images and JSON resourcesused to generate passes

Passbook

AppleAPNS serverspush update notification

webservice

notificationof change

register pass : pushToken

certificate for signing passes

Update database

sign-pass

dissociate pass

"webServiceURL" : "https://example.com/passes/", "authenticationToken" : "vxwxd7J8AlNNFPS8k0a0FfUFtq0ewzFdc",

Scanner

P.O.S.

register pass : pushToken

Page 21: PassKit on iOS 6

Updates with APNS ii

• REST web service : Apple’s defined format

• Register : when pass is added

• Delete : shredder!

• Update : build and send new data (same serial #)

• Get Serial Numbers for Device

• Error Logging (optional)

POST webServiceURL/version/devices/deviceLibraryIdentifier/registrations/passTypeIdentifier/serialNumberpushToken

DELETE webServiceURL/version/devices/deviceLibraryIdentifier/registrations/passTypeIdentifier/serialNumber

GET webServiceURL/version/devices/deviceLibraryIdentifier/registrations/passTypeIdentifier?passesUpdatedSince=tag

GET webServiceURL/version/passes/passTypeIdentifier/serialNumber

POST webServiceURL/version/log

Page 22: PassKit on iOS 6

Your server

images and JSON resourcesused to generate passes

pass & devicedatabase

Passbook

Conduit Apps

Companion Apps

MailSafari

(others)

AppleAPNS servers

Your app

push update notification

request changed

data

webservice

notificationof change

register pass

generate & sign pass

Add Pass

Add Pass

email attachmentsweb links

make changes to passcertificate for signing passes

Scan Pass

Update database Scanner

P.O.S.

sign-pass

Review

Page 23: PassKit on iOS 6

Cross-platform?

• Cross-platform C# library for reading & writing PKPass fileshttps://github.com/Redth/PassKitSharp

• Cross-platform C# library for barcode scanninghttps://github.com/Redth/ZXing.Net.Mobile

• Push Notifications C# library for Push Notificationshttps://github.com/Redth/PushSharp/

@redth

PassWallet for Android(Attido Mobile)