Configure QR Code Login for iOS

To configure QR code login for an iOS app, follow these steps.

The iOSNativeSwiftTemplate includes sample code for setting up QR code login. Find iOSNativeSwiftTemplate in Mobile SDK’s GitHub repository: github.com/forcedotcom/SalesforceMobileSDK-Templates.

To create an app by using the template, see Creating an iOS Project with Forcedroid.

To configure your app to open the login link when a user scans the QR code in the camera app, see Apple’s documentation.

To request camera access and scan QR codes on your app, update the camera app’s usage description according to Apple’s documentation: NSCameraUsageDescription | Apple Developer Documentation

In iOSNativeSwiftTemplate, QR code login features are labeled by this comment: “Log in via Salesforce UI Bridge API generated QR codes.”

To enable QR code login features in iOSNativeSwiftTemplate, modify these files.

To configure the QR code login setup to run on app initialization, go to the init method and uncomment the call to setupQrCodeLogin.

To customize the QR code login’s URL format, use the sample code provided in SceneDelegate.useQrCodeLoginUrl(_: ).

When using a QR code login URL generated by the UI Bridge API, you can choose between Mobile SDK’s reference format or a custom format.

If you’re using our reference format, make sure to fill in these variables.

If you’re using a custom format, set isQrCodeLoginUsingReferenceUrlFormat to false, and then provide the URL handling logic in SceneDelegate.useQrCodeLogInUrl. To modify the QR code login URL format, you can customize the values in setupQrCodeLogin by following the comments provided in the source code.

To allow your app to receive QR code login links from external QR code readers, uncomment the calls to useQrCodeLogInUrl in the scene(_: openURLContexts:) and scene(_: willConnectTo: options:) methods.