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.
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)
- Create a new project in the Google API Console.
- Enable the Gmail API for your project.
- Create OAuth 2.0 credentials (iOS option) and complete the OAuth Consent Screen setup.
To use Gmail OAuth in production, you must obtain Google's review and approval of your application.
- Set the Client ID via
BREReceiptManager.shared.googleClientId. - 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
}
}
- 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)
- Register a new application in the Azure Portal.
- Add the
Mail.Readpermission under Microsoft Graph. - Set the Client ID and redirect URI via
BREReceiptManager.shared.outlookClientIdandBREReceiptManager.shared.outlookRedirectUri. - 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
}
}
Unlink an Account
BREReceiptManager.shared().signOut(forProvider: .gmail)