Suppose i have a pass in my passbook app. And wanted to share the pass with one of my friends.
In my app, if I mail the .pkpass data (received from server) to my friend, then its recognised by the device as a pass.
[controller addAttachmentData:data mimeType:@"application/vnd.apple.pkpass" fileName:@"Pass.pkpass"];
Suppose i have the .pkpass file in my document directory or application bundle, then by changing that file to data and then mailing it, also works fine.
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"walmart" ofType:@"pkpass"];
NSData *data = [[NSData alloc] initWithContentsOfFile:filePath];
[controller addAttachmentData:data mimeType:@"application/vnd.apple.pkpass" fileName:@"Pass.pkpass"]
But when i use the following code then it doesn't work.
_passLibrary = [[PKPassLibrary alloc] init];
_passArray = [_passLibrary passes];
PKPass *pass = _passArray[0];
NSData *data = [[NSData alloc] initWithContentsOfURL:[pass passURL]];
[controller addAttachmentData:data2 mimeType:@"application/vnd.apple.pkpass" fileName:@"Pass.pkpass"];
One more way in my mind is sharing via Bluetooth. But it doesn't make sense if I dont have the accurate pass data. From all the above specified approaches, the third one makes sense (coding quality wise) but the data is not as required.
Also please suggest me the other ways to make the sharing possible.
If you and your buddies are using the same app you can keep a list of passes on your server, mark them as sharable, show the list of sharable passes and allow them to get the pass directly from the server; a standard server<->app kind of feature.
If you want to use bluetooth then you're a little outside my comfort zone, but since the .pkpass file is just a blob of characters you can transfer the file/blob across the ether and instantiate it with the PassKit API as per the docs.