I just finished testing the new PassHound API for IOS and it rocks!

I was able to create a quick demo app that pulled in data from my LinkedIn account, create a passbook and add it to my passes on my iPhone in a couple hours. The API is pretty easy to use after you read the documentation on the calls, below is the code snippet for using the  PassHound API.

 NSString *sid = @"0";
        NSString *sname = [NSString stringWithFormat:@"LI-%@", [profile objectForKey:@"id"]];
        NSURL *surl = [NSURL URLWithString:[profile objectForKey:@"pictureUrl"]];
        UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:surl]];

if ([sharedManager login:@"myemail@gmail.com" password:@"password"]) {
            NSData *imageData = UIImagePNGRepresentation(image);
            if ([sharedManager createPass:sname fromTemplate:@"LinkedIn"] ) {
                [sharedManager postThumbnailImage: imageData forImage:@"thumbnail.png" forPass:sname];
                NSArray *passes = [sharedManager getPasses];
                // Obtain the key/values for the pass
                if (![sharedManager editPass:[NSString stringWithFormat: @"primaryFields_name_value=%@&secondaryFields_headline_value=%@&auxilaryFields_industry_value=%@&backFields_specialties_value=%@&backFields_summary_value=%@&backFields_profileUrl_value=%@&headerFields_connects_value=%@&barcode_message=%@&backFields_location_value=%@",
                                              [profile objectForKey:@"formattedName"],
                                              [profile objectForKey:@"headline"],
                                              [profile objectForKey:@"industry"],
                                              [profile objectForKey:@"specialties"],
                                              [profile objectForKey:@"summary"],
                                              [profile objectForKey:@"publicProfileUrl"],
                                              [profile objectForKey:@"numConnections"],
                                              [profile objectForKey:@"publicProfileUrl"],
                                              [[profile objectForKey:@"location"] objectForKey:@"name"]
                                              ] forPass:sname]) {
                    NSLog(@"%@",[sharedManager getError]);
                }
            }

            // Obtain the pass data
            NSData *passData = [sharedManager downloadPass:sid];
            NSError* error = nil;
            PKPass *newPass = [[PKPass alloc] initWithData:passData error:&error];
            PKAddPassesViewController *addController =
            [[PKAddPassesViewController alloc] initWithPass:newPass];
            addController.delegate = self;
            [self presentViewController:addController animated:YES  completion:nil];
        }
Advertisements