Add event ticket to Apple wallet? - ios

I am developing event app, in which, once user done with booking event ticket then, we have to add that pass to Apple wallet.
I am following below link to design my pass, https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/PassKit_PG/Creating.html
But the problem is I have completed the JSON, but how can I add ticket to wallet using code.

You just need to follow the steps described in the Apple documentation:
Create a directory structure, containing the pass.json file, images etc.
Create an SHA-1 hash of every file and store it in manifest.json on top-level
ZIP the contents of the directory
Distribute the file using application/vnd.apple.pkpass MIME type
Once you get the file into your application:
Read the file (e.g. using Data(contentsOf:))
Hand it into PKPass(data:)
Present the pass to the PKAddPassesViewController

Related

Creating passbook passes in iOS app

Is it possible to create pkpass in app? I have watched a few wwdc and searched online. It say it require signing and it can't be created in app. Is it correct? If not, is there a way to create in app?
The simple answer is yes, but you probably don't want to. I don't see what would stop you creating and signing a PKPass file in ObjectiveC or Swift.
The reason you wouldn't want to do this is security. When a pass is created, it's manifest is signed with a private key. This ensures that you can trust the vendor and it also provides legal safeguards. If you put were to create the private key into the pass it could be extracted and use to create similar Passes or even replace your own passes.

How to enable open of my own custom file type on iOS

I have an iOS app that I want to be able to send and receive instances of its own file type. The flow would be:
User 1 selects a Share function in the app. This generates a file of my type (say, file.myextension) and shares it using a UIActivityViewController. They send it somehow to User 2 (AirDrop, email, whatever).
User 2 receives the file and opens it. The system offers to open it using my app.
I've got the first part working. I can generate file.myExtension and give the UIActivityViewController a file URL to it. This shows up correctly in AirDrop on user 1's device, and I can transfer the file using AirDrop or email or whatever. But the receiving device refuses to show my app as an option to open the file.
I have tried:
Declaring Exported and Imported UTIs and a Document Type as per this Apple Q&A. I've triple-checked that all the IDs are the same and all the plist keys are spelled correctly.
I've tried both an Exported and Imported UTI alone (with a Document Type). This article seems to say that the Imported one is what I want if I want to open a file type. This SO answer says that registering a type I own and want to open means I just want Exported. Neither on its own worked.
My question: what do I have to do to be able to open a file extension that I own on iOS? Do I define both Imported and Exported UTIs, along with a Document Type? Just one of exported or imported? Any unexpected required attributes?
The CFBundleDocumentTypes key is what you need. It should be an Array, and each item in the array should be a Dictionary. Each Dictionary should contain the following keys:
CFBundleTypeIconFiles (Array of Strings)
CFBundleTypeName (String)
CFBundleTypeRole (String)
LSHandlerRank (String)
LSIsAppleDefaultForType (Boolean)
LSItemContentTypes (Array of Strings)
Here is what it looks like for my application (stuff blacked out to avoid revealing my company's identity):
Figured it out. One key detail not explicit in the docs is that the last part of the types in the Document Type section has to match the file extension you choose.

how to add passes that get dynamic info from my app to wallet from in swift?

I created the my own .pkpass file with dummy data
I need to change the data in the pass according to the data in the app
like boarding pass
if I missed something , could please help me ?
You will require a new .pkpass bundle for every change to the pass.
A new bundle will need to be signed. For security reasons, this should not take place on the device as it risks compromising your Pass Type ID certificate.
When you want to change the data, you should request a new pass bundle from your server and use the PassKit APIs to replace the pass in the Wallet.
You need to implement full loop system according to Apple Passbook/wallet standard or at least you have to like this.
in pkpass file add webService, serialNumber (text and number), authenticationToken (text and number at least 16 characters), passTypeIdentifier and teamIdentifier value (register and download certification file from apple developer account). It has to be https and point to your server.
create push notification system to devices that keep your passes by using certification file (cer) and create p12 and pem files (you can find how to make it here: Update Passbook wallet failed to connect)
create update web service to manage request from device and return new pkpass file to devices
others that: you have to make web service to manage register, update and delete method from devices.

is it possible to develop pass creator?

i investigate development for Apple Passbook. i've found that if you have something to perform as a pass to your subscribers, you should create special .pkpass files and distribute them variously. But is it possible to create your own passes in iOS application and add them to Passbook? For example, i have barcode, all additional info, so i want application user to configure his own pass.
It's certainly technically possible to develop your own pass creation App, however to create a .pkpass bundle entirely within an App would require you to embed your Pass ID Private Key within the App which presents a huge security risk.
In practice, your App should send the pass data to your web server which should compile the .pkpass bundle and transfer the bundle back to your App to add to Passbook.
The Apple Pass Kit Framework reference gives you everything you need to accept a pass from your web server that contains info that your user has provided to your App.

How can I transfer files from one application to another in the same iOS device?

I am writing an iOS application that performs conversion of a file saved by another application on the same device to another format. How can I transfer files from one application to another in the same device? Note that the files are non-textual files.
UIDocumentInteractionController is your friend.
Basically it works like this:
App 1 registers as being able to handle files of type XYZ
App 2 implements UIDocumentInteractionController and will give users the options to "send the file to App1" (I believe this has to be user activated)
App 1 implements -(BOOL)application:openURL:sourceApplication:annotation: and deals with the transferred file which will be saved in your Documents/Inbox directory. From there you can copy the file elsewhere and then manipulated it, making sure you clean up by getting rid of the original one saved on the Inbox folder.
Class reference available here
Document interaction programming guide available here
If you are developing both apps, you can store shared information in the keychain as long as your bundle identifiers conform to the same bundle seed id. See here for more info. Of course, if you are making both applications, you can use a URL scheme to pass in base64 encoded data as well.
Update: As rog said below, UIDocumentInteractionController is great, but it is only available for 4.2 and up, so you are cutting out a major portion of your users if you want to use it.

Resources