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.

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.


Gmail (OAuth)

  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)
}

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
}
}

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
}
}

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
}
}

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