Skip to main content

iOS Account Linking

Instructions to integrate the BlinkEReceipt iOS SDK for account linking and background order retrieval.

Installation​

Installation instructions can be found in our Installation Guide.


SDK Setup​

Initialize in AppDelegate​

Set your license keys and instantiate BRAccountLinkingManager as early as possible — it downloads the most recent parsing code in the background:

import UIKit
import BlinkReceipt
import BlinkEReceipt

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
BRScanManager.shared().licenseKey = "YOUR-LICENSE-KEY"
BRScanManager.shared().prodIntelKey = "YOUR-PROD-INTEL-KEY"
BRAccountLinkingManager.shared()
return true
}
}
note

A licenseKey or prodIntelKey can be obtained by emailing blinkreceipt@microblink.com.

Import Headers (Objective-C)​

For account linking:

#import <BlinkEReceipt/BRAccountLinkingManager.h>
// or, for Carthage / standalone:
#import <BlinkEReceiptStatic/BRAccountLinkingManager.h>

For e-receipt parsing:

#import <BlinkEReceipt/BREReceiptManager.h>
// or, for Carthage / standalone:
#import <BlinkEReceiptStatic/BREReceiptManager.h>

Account Linking​

Account Linking connects users' retailer accounts to retrieve their order history. The SDK supports two authentication flows.

Create an Account Connection​

Host App Authentication​

Your app provides a native credential prompt. All interactions with the merchant happen in a hidden webview — the webview only surfaces when 2FA, CAPTCHA, or other user input is required.

let connection = BRAccountLinkingConnection(retailer: .walmart, username: "user@domain.com", password: "secure-password")
connection.configuration.dayCutoff = 30

Retailer Webview Authentication​

The SDK presents the merchant's own authentication page in a webview. No native credential UI is needed — the webview dismisses automatically after successful authentication.

let connection = BRAccountLinkingConnection(retailer: .walmart)
connection.configuration.dayCutoff = 30

Switch between the two modes on an already-linked connection:

if let connection = BRAccountLinkingManager.shared().getLinkedRetailerConnection(.walmart) {
connection.webviewAuthEnabled = true // use Retailer Webview Authentication
connection.webviewAuthEnabled = false // use Host App Authentication
BRAccountLinkingManager.shared().update(connection)
}
let connection = BRAccountLinkingConnection(retailer: account)
let taskId = BRAccountLinkingManager.shared().linkAccount(with: connection) { error, viewController, sessionId in
if error == .verificationNeeded {
// Display viewController for 2FA, CAPTCHA, or other user input
} else if error == .verificationCompleted {
// Dismiss the previously presented viewController
} else if error == .none {
// Account linked successfully
} else if error == .noCredentials {
// Error: credentials not provided
} else if error == .invalidCredentials {
// Error: credentials are invalid
} else if error == .cancelled {
// Operation cancelled
} else if error == .webViewClosed {
// Operation terminated because the webview was dismissed
}
}

Re-authenticate a Connection​

Check isAuthenticated before re-authenticating to avoid unnecessary requests:

let retailer = BRAccountLinkingRetailer.walmart

if let connection = BRAccountLinkingManager.shared().getLinkedRetailerConnection(retailer) {
if connection.isAuthenticated { return }
}

let taskId = BRAccountLinkingManager.shared().loginUser(forLinkedRetailer: retailer) { error, viewController, sessionId in
if error == .verificationNeeded {
// Display viewController for 2FA or CAPTCHA
} else if error == .verificationCompleted {
// Dismiss the previously presented viewController
} else if error == .none {
// Re-authentication successful
}
}

Grab New Orders​

Once a retailer is linked and authenticated, retrieve new orders:

let taskId = BRAccountLinkingManager.shared().grabNewOrders(for: .walmart) { retailer, order, remaining, viewController, errorCode, sessionID in
if errorCode == .verificationNeeded {
// Display viewController for 2FA or CAPTCHA
} else if errorCode == .verificationCompleted {
// Dismiss the previously presented viewController
} else if errorCode == .none {
// order contains the retrieved purchase data
if remaining <= 0 {
// All orders fetched
}
} else {
// Fetch failed — check errorCode for details
}
}
note

The SDK tracks the last successful fetch date per retailer. Each call only retrieves orders since the last check, up to the dayCutoff you set (default: 15 days).

Grab New Orders in Background​

Account Linking supports periodic background order retrieval via iOS background tasks.

Register a task identifier (see Apple's documentation) and pass it to the SDK:

BRAccountLinkingManager.shared().enableBackgroundFetch(withIdentifier: taskIdentifier)

Implement backgroundFetchCompletion to receive results from background jobs:

BRAccountLinkingManager.shared().backgroundFetchCompletion = { retailer, errorCode, sessionId, order in
// Same handling as Grab New Orders above
}

Full AppDelegate example:

import UIKit
import BlinkReceipt
import BlinkEReceipt

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
BRScanManager.shared().licenseKey = "YOUR-LICENSE-KEY"
BRScanManager.shared().prodIntelKey = "YOUR-PROD-INTEL-KEY"

let taskIdentifier = "com.yourapp.background-fetch"
BRAccountLinkingManager.shared().enableBackgroundFetch(withIdentifier: taskIdentifier)

BRAccountLinkingManager.shared().backgroundFetchCompletion = { retailer, errorCode, sessionId, order in
// Handle background order results
}
return true
}
}

SDK Full Reference​

Some of the symbols referenced in these docs (such as BRScanResults and BRProduct) are fully documented in the BlinkReceipt SDK Full Reference.