Skip to content

Instantly share code, notes, and snippets.

@EchoAbstract
Created June 19, 2012 17:01
Show Gist options
  • Save EchoAbstract/2955286 to your computer and use it in GitHub Desktop.
Save EchoAbstract/2955286 to your computer and use it in GitHub Desktop.
Passbook
// To create a coupon or storecard feature in your app
// you can do the following
@interface Card : NSObject <KCSPersistable>
@property (nonatomic, retain) NSString *cardId;
@property (nonatomic, retain) NSString *code;
@property (nonatomic, retain) NSString *cardName;
@property (nonatomic, retain) NSString *firstName;
@property (nonatomic, retain) NSString *lastName;
@end
@implementation Card
@synthesize cardId;
@synthesize code;
@synthesize cardName;
@synthesize firstName;
@synthesize lastName;
// Kinvey: Mapping function
- (NSDictionary *)hostToKinveyPropertyMapping
{
// So it's only initialized once
static NSDictionary *mapping = nil;
if (mapping == nil){
mapping = [NSDictionary dictionaryWithObjectsAndKeys:
@"_id", @"cardId", // cardId maps to _id
@"code", @"code",
@"firstName", @"firstName",
@"lastName", @"lastName",
@"cardName", @"cardName", nil];
}
return mapping;
}
@end
// Sometime later... in a view controller...
- (void)performApplicationLogic
{
// Your code here...
KCSCollection *cards = [[KCSClient sharedClient] collectionFromString:@"cards"
withClass:[Card class]];
KCSQuery *q = [KCSQuery query];
[q addQueryOnField:@"firstName" withExactMatchForValue:self.firstNameTextField.text];
[q addQueryOnField:@"lastName" withExactMatchForValue:self.lastNameTextFiled.text];
cards.query = q;
[cards fetchWithDelegate:self];
// Your code continues...
}
// In your delegate
- (void)collection:(KCSCollection *)collection didCompleteWithResult:(NSArray *)result
{
for (Card *card in result){
// Build a card here
// Encode our code as a QR-Code
// (Using: http://myang-git.github.com/QR-Code-Encoder-for-Objective-C/ as an example)
DataMatrix* qrMatrix = [QREncoder encodeWithECLevel:QR_ECLEVEL_AUTO
version:QR_VERSION_AUTO
string:card.code];
// Render to an image
UIImage* qrcodeImage = [QREncoder renderDataMatrix:qrMatrix
imageDimension:qrcodeImageDimension];
// Use the first name and last name to finish building your card here,
// then display everything
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment