Skip to main content

Add Custom view to your project

  1. Create a class that conforms to ChoicelyExternalViewControllerFactory protocol:
    class YourCustomViewControllerFactory: ChoicelyExternalViewControllerFactory {
    
        func createViewController(choicelyNavigationitem: ChoicelyNavigationItem?) -> ChoicelyController? {
            return nil
        }
    }
    
  2. Declare all your custom views usage inside it’s createViewController() method:
    let yourCustomUrl = "choicely://special/your_custom_url"
    let internalUrl = choicelyNavigationitem?.internalUrl
    
    if internalUrl.contains(yourCustomUrl) == true {
      return YourCustomViewController()
    }
    
    // In order to return YourCustomViewController make it a subclass of ChoicelyViewController.
    
    Custom navigation URLs like "choicely://special/your_custom_url" can be set and configured in Choicely Studio.
    This is how you can create custom navigation URLs:
    How to use navigation iOS
  3. Set the custom url, click “Add Navigation” and save the changes by clicking “Update” button in the top right corner.
  4. Here is the example of fully configured ChoicelyExternalViewControllerFactory:
    import ChoicelyCore
    
    class YourCustomViewControllerFactory: ChoicelyExternalViewControllerFactory {
    
      func createViewController(choicelyNavigationitem: ChoicelyNavigationItem?) -> ChoicelyController? {
        let yourCustomUrl = "choicely://special/your_custom_url"
        let internalUrl = choicelyNavigationitem?.internalUrl
    
        if internalUrl.contains(yourCustomUrl) == true {
          return YourCustomViewController()
        }
    
        return nil
      }
    }
    
  5. Create an instance of YourCustomViewControllerFactory class and just before ChoicelySDK.initialize(...) assign it to ChoicelySDK.settings.externalViewControllerFactory:
    ChoicelySDK.settings.externalViewControllerFactory = YourCustomViewControllerFactory()
    
    To learn more about other ChoicelySDK settings explore them in XCode with (⌥)+click.
  6. That’s it! You’re ready to use your custom views.
    You can mix Choicely content like Articles and Surveys with your own UI logic inside one custom view.