SDK

Scannables

This functionality will allow your app to present content after they have scanned a NFC Tag or QR Code (we use QR Codes whenever the device does not support NFC). This could be extremely useful if you're looking to extend physical objects with engaging content pretty much the same way you do when sending a notification.

Before you can start using this functionality you will need to create one or more tags in our dashboard. This is covered in our guides located here.

For this functionality you'll need to add the following to your app's .plist file:

ios nfc camera privacy entries

You must provide a text describing why your need to use NFC capabilities and why you need to use the camera in your app. Please note that older devices may not have NFC support. When NFC is not supported or disabled, our library will fall back to scanning QR codes.

In most cases you will want to start scanning a tag whenever the user opens your app and clicks a button in your UI. This would be done from one your app's view controllers like this:

@IBAction private func onButtonClicked(_: Any) {
    Notificare.shared.scannables().startScannableSession(controller: navigationController!)
}

You can also check manually if the device supports NFC scannable sessions and act accordingly.

if Notificare.shared.scannables().canStartNfcScannableSession {
    Notificare.shared.scannables().startNfcScannableSession()
} else {
    Notificare.shared.scannables().startQrCodeScannableSession(controller: navigationController!, modal: true)
}

Once the user taps a NFC tag or scans a QR code, your app will be responsible for handling the results. In that view controller you would then implement the following:

class MainViewController : UIViewController, NotificareScannablesDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.

        Notificare.shared.scannables().delegate = self
    }

    func notificare(_ notificareScannables: NotificareScannables, didDetectScannable scannable: NotificareScannable) {
        guard let notification = scannable.notification else {
            // This scannable doesn't contain a notification.
            return
        }

        Notificare.shared.pushUI().presentNotification(notification, in: navigationController!)
    }

    func notificare(_ notificareScannables: NotificareScannables, didInvalidateScannerSession error: Error) {
        // Handle the error.
    }
}

This will make sure that as soon as the NFC tag is scanned your app will be able to handle results and present the content accordingly.