Skip to content

Instantly share code, notes, and snippets.

@dpanzer
Last active November 26, 2020 07:23
Show Gist options
  • Save dpanzer/02f2d763c5bb19e985b66ea245ae1163 to your computer and use it in GitHub Desktop.
Save dpanzer/02f2d763c5bb19e985b66ea245ae1163 to your computer and use it in GitHub Desktop.
@implementation ViewController
//this only needs to be done *ONCE* unless the user chooses to unlink the account at some later time
- (IBAction)btnLinkTouched:(id)sender {
[[BREReceiptManager shared] setupIMAPForProvider:BREReceiptProviderGmail
viewController:self
withCompletion:^(BRSetupIMAPResult result) {
if (result == BRSetupIMAPResultCreatedAppPassword) {
NSLog(@"Account linking successful");
//At this point you would store something internally to indicate that the user has a linked account
//Such as using NSUserDefaults or the keychain or your own backend...
}
}
}
//this would be done every time you want to grab new email from the user's linked account, which could be based on a user action
//like I have it set up here (a button press) OR could be something you trigger behind the scenes at any time
- (IBAction)btnGrabEmails:(id)sender {
//Here you might first add a check to make sure that the user actually does have a linked account, which would be based on your own
//internal state, as discussed above
//if you wanted you could first verify the account by calling `[[BREReceiptManager shared] verifyImapCredentials:]`
//and then only upon verification success, you would call the below
[[BREReceiptManager shared] getEReceiptsWithCompletion:^(NSArray *scanResults, NSError *error) {
NSLog(@"Found %lu new e-receipt orders", (unsigned long)scanResults.count);
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment