Skip to main content

iOS Email Linking

The BlinkEReceipt SDK supports parsing e-receipts from a growing list of retailers and the following mail providers: Gmail, Outlook, Yahoo, and AOL.

The SDK supports multiple linked accounts simultaneously, with the restriction that at most one Gmail OAuth account and at most one Outlook OAuth account can be linked at any time. Gmail IMAP is the recommended way to link Gmail; Gmail OAuth is deprecated.

note

Both BRScanManager.sharedManager.licenseKey and BRScanManager.sharedManager.prodIntelKey are required for e-receipt parsing to function. Contact support@microblink.com if you do not have a prodIntelKey.


Outlook (OAuth)​

  1. Register a new application in the Azure Portal.
  2. Add the Mail.Read permission under Microsoft Graph.
  3. Set the Client ID and redirect URI via BREReceiptManager.shared.outlookClientId and BREReceiptManager.shared.outlookRedirectUri.
  4. Invoke authentication:
BREReceiptManager.shared().beginOAuth(forProvider: .outlook, withViewController: self) { error in
if error == nil {
// Account successfully authenticated
}
}

Gmail (IMAP)​

Gmail IMAP is the recommended Gmail integration. It uses the same IMAP setup flow as Yahoo and AOL, and does not require Google API Console credentials or Google's OAuth app review.

let account = BRIMAPAccount(gmailIMAP: ())

BREReceiptManager.shared().setupIMAP(for: account, viewController: self) { result, emailAccount, error in
if result == .saved || result == .createdAppPassword {
// Account successfully linked
}
}

To collect each authentication step in a webview instead of the default flow, set webviewAuthEnabled before calling setupIMAP:

account.webviewAuthEnabled = true

See BRIMAPAccount for the Gmail IMAP initializer and setupIMAP(for:viewController:withCompletion:).


Yahoo (IMAP)​

Yahoo requires an app-specific password — direct account passwords are not supported.

let account = BRIMAPAccount(provider: .yahoo)
account.username = "user@yahoo.com"
account.password = "app-specific-password"

BREReceiptManager.shared().setupIMAP(for: account) { result in
if result == .connected {
// Account successfully linked
}
}

AOL (IMAP)​

let account = BRIMAPAccount(provider: .aol)
account.username = "user@aol.com"
account.password = "app-specific-password"

BREReceiptManager.shared().setupIMAP(for: account) { result in
if result == .connected {
// Account successfully linked
}
}

Gmail (OAuth)​

warning

Gmail OAuth is deprecated. Use Gmail IMAP for new integrations.

  1. Create a new project in the Google API Console.
  2. Enable the Gmail API for your project.
  3. Create OAuth 2.0 credentials (iOS option) and complete the OAuth Consent Screen setup.
warning

To use Gmail OAuth in production, you must obtain Google's review and approval of your application.

  1. Set the Client ID via BREReceiptManager.shared.googleClientId.
  2. Invoke the OAuth flow from your view controller:
BREReceiptManager.shared().beginOAuth(forProvider: .gmail, withViewController: self) { error in
if error == nil {
// Account successfully authenticated
} else {
// Failed to authenticate
}
}
  1. Handle the OAuth response in your app delegate:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
return BREReceiptManager.shared().handleOpen(url, sourceApplication: options[.sourceApplication] as? String)
}

Grab New E-Receipts​

Once an account is authenticated, retrieve e-receipts:

BREReceiptManager.shared().grabNewOrders { scanResults, remaining, error in
if let results = scanResults {
// Process BRScanResults
if remaining <= 0 {
// All e-receipts have been fetched
}
} else if let error = error {
// Handle error
}
}

Auto-Scrape​

Auto-Scrape runs the e-receipt scrape automatically in the background on a periodic schedule, so your app doesn't have to grab e-receipts manually. It is a host-controlled permission gate — off by default — that, once enabled, periodically scrapes the user's linked Gmail IMAP accounts and reports each account's jobId through a completion block.

Register the background task at launch (in application:didFinishLaunchingWithOptions:), then opt the user in:

// 1. Register the task once at launch, regardless of opt-in. The identifier must be unique and
// listed under BGTaskSchedulerPermittedIdentifiers in your Info.plist.
BREReceiptManager.shared().enableAutoScrape(withIdentifier: "com.yourapp.auto-scrape")

// 2. Receive each account's jobId from the background scrape.
BREReceiptManager.shared().autoScrapeCompletion = { jobId, error in
// background context — capture weakly, don't touch UIKit directly
}

// 3. Opt the user in (persist this choice and re-apply it at launch).
BREReceiptManager.shared().autoScrapeEnabled = true

See the Auto-Scrape SDK reference for the full API: the permission gate, scrape interval, results completion block, and provider scope.


BREReceiptManager.shared().signOut(forProvider: .gmail)