Skip to content

User Consent View

FUIUserConsentViewController

open class FUIUserConsentViewController: UIViewController, FUIUserConsentPageViewControllerDelegate, ConsentPageDisplayDelegate

This UIViewController is used to display a series of user consent screens modally during the process of onboarding. The property forms must be supplied, which is an array of objects of the two classes that conform to the FUIUserConsentForm protocol, namely FUISinglePageUserConsentForm and FUIMultiPageUserConsentForm. The Fiori for iOS SDK takes these forms and displays them modally as single or multipage user consent screens using the FUIUserConsentViewController. A user consent screen contains a title, a brief information on the topic for which the user consent is required and a link to more details. There are 2 buttons in the toolbar, "Agree" and "Deny", if the consent form is mandatory or "Agree" and "Not Now", if the consent form is optional. In the case of a mandatory form, the user can proceed to the next step of onboarding only when they agree to the terms stated in the form. In the case of an optional form, the user can choose to click the "Not Now" button and proceed with the onboarding. In addition, there is a "Cancel" button in the navigation bar. The toolbar buttons and the cancel button invoke the FUIUserConsentViewControllerDelegate methods which can be used to handle the application logic based on the user input. If the form is a multi-page consent form, only the last page in the form displays the toolbar and cancel buttons. Each consent form has the title property,body containing the details, an actionTitle, which when tapped invokes the actionHandler. There are also the titleAttributedText, bodyAttributedText and actionTitleAttributedText properties, which when supplied take precedence over the title, body and actionTitle properties. For example, when both titleand titleAttributedText are supplied, only titleAttributedText is displayed.

Image

let spForm = createSinglePageForm()
spForm.isRequired = false
let mpForm = createMultiPageForm()
mpForm.isRequired = false
let forms = [spForm,mpForm] as [Any]

(UIApplication.shared.delegate as! AppDelegate).inUserConsentScreen = true
let ctrller = FUIUserConsentViewController()
ctrller.delegate = self
ctrller.forms = forms as! [FUIUserConsentForm]
self.navigationController?.present(ctrller, animated: true, completion: nil)

func createSinglePageForm()->FUISinglePageUserConsentForm {
let singlepageform = FUISinglePageUserConsentForm()
singlepageform.title.text = "Data Privacy"
singlepageform.body.text = "Detailed text about how data privacy pertains to this app and why it is important for the user to enable this functionality"
singlepageform.actionTitle.text = "Learn more about Data Privacy"
singlepageform.actionHandler = { controller in
let alert = UIAlertController(title: "Want Data Privacy?", message: "Be wise about your data", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
controller.present(alert, animated: true, completion: nil)
}
return singlepageform
}

func createMultiPageForm()->FUIMultiPageUserConsentForm {
let page1 = FUIUserConsentPage()
page1.title.text = "Data Privacy"
page1.body.text = "Detailed text about how data privacy pertains to this app and why it is important for the user to enable this functionality"
page1.actionTitle.text = "Learn more about Data Privacy"
page1.actionHandler = { controller in
let alert = UIAlertController(title: "Data Privacy", message: "Alert for Data Privacy Page", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
controller.present(alert, animated: true, completion: nil)
}

let page2 = FUIUserConsentPage()
page2.title.text = "Security"
page2.body.text = "Detailed text about how data privacy pertains to this app and why it is important for the user to enable this functionality. "
page2.actionTitle.text = "Learn more about Data Privacy"
page2.actionHandler = { controller in
let alert = UIAlertController(title: "Security", message: "Alert for data security page", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
controller.present(alert, animated: true, completion: nil)
}

let page3 = FUIUserConsentPage()
page3.title.text = "Consent"
page3.body.text = "Detailed text about how data privacy pertains to this app and why it is important for the user to enable this functionality"
page3.actionTitle.text = "Learn more about Data Privacy"
page3.actionHandler = { controller in
let alert = UIAlertController(title: "Consent", message: "Alert for consent page", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
controller.present(alert, animated: true, completion: nil)
}

let userconsentpages = [page1,page2,page3]
let multipageform = FUIMultiPageUserConsentForm(pages: userconsentpages)
return multipageform
}

Application should also implement the FUIUserConsentViewControllerDelegate protocol, which provides the delegate methods that handle the application flow based on whether the user agrees, disagrees or cancels the form. It is important that the FUIUserConsentViewController, passed in as the parameter viewController must be dismissed first as shown below, before proceeding with any other application logic based on the user response to the forms.

```swift

func userConsentViewController( viewController: FUIUserConsentViewController, didCancelConsentForms forms: [FUIUserConsentForm]) {

1
2
3
4
5
6
viewController.dismiss(animated: true, completion: nil)

let alert = UIAlertController(title: "Cancelled", message: "User cancelled Onboarding", preferredStyle: UIAlertControllerStyle.alert)
(UIApplication.shared.delegate as! AppDelegate).inUserConsentScreen = false
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)

}

func userConsentViewController( viewController: FUIUserConsentViewController, didReceiveResponseToConsentForms forms: [FUIUserConsentForm]) {

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
(UIApplication.shared.delegate as! AppDelegate).inUserConsentScreen = false
var NumAccepted = 0
for form in forms  {
    if (form.isUserAccepted) {
        NumAccepted = NumAccepted + 1
    }
}
viewController.dismiss(animated: true, completion: nil)
if (NumAccepted > 0) {
    let alert = UIAlertController(title: "Status", message: "User accepted \(NumAccepted) form(s)", preferredStyle: UIAlertControllerStyle.alert)
    alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
    self.present(alert, animated: true, completion: nil)
}

}

Note that the user consent screen orientations are supported for iPad portrait and landscape
orientation and iPhone portrait orientation only. Since the screen is not supported in iPhone landscape
orientation, the app needs to switch to portrait mode before presenting the screen and the `AppDelegate`
needs to lock the screen orientation when these screens are shown, similar to the following code
snippet.

In app's `AppDelegate`:

```swift

public var inUserConsentScreen: Bool = false

// Implement this function to support only portrait orientation when FUIUserConsentScreen is displayed in iPhone.
func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
   if !inUserConsentScreen {
       return .allButUpsideDown
   } else {
       return .portrait
   }
}

Before presenting the FUIUserConsentViewController:

// Let `AppDelegate` know that we are entering the screen
(UIApplication.shared.delegate as! AppDelegate).inUserConsentScreen = true

// Present the screen
self.navigationController?.present(ctrller, animated: true, completion: nil)

After dismissing the FUIUserConsentViewController screen:

viewController.dismiss(animated: true, completion: nil)

// Let `AppDelegate` know that we are exiting the view
(UIApplication.shared.delegate as! AppDelegate).inUserConsentScreen = false

Theming

Supported class paths:

fdlFUIUserConsentPageView_title {}
fdlFUIUserConsentPageView_body {}
fdlFUIUserConsentPageView_actionTitle {}

Supported properties:

font-color: Color;
font-style: UIFontTextStyle;
text-line-clamp: Integer;
text-align: NSTextAlignment;

Supported NavigationBar class paths:

fdlFUIUserConsentViewController_navigationBar {}

Supported NavigationBar properties:

bar-tint-color: Color;
background-color: Color;

Attention

The delegate object with type FUIUserConsentViewControllerDelegate is declared as a weak reference. On deallocation it will be automatically set to nil. To keep it alive as expected, developer should retain the delegate object during the whole execution scope.


Last update: April 14, 2021