Working with XMMContentBlocks - xamoom/xamoom-ios-sdk GitHub Wiki
At this page you can find a explanation, how to display a loaded content and how to handle the XMMContentBlocks class.
Initialization
First, import our SDK to your UIViewController.
import XamoomSDK
XMMContentBlocks needs a UITableView and a XMMEnduserApi in the constructor to get successfully initialized. So implement a UITableView in your .storyboard, .nib or programmatically and initialize the XMMContentBlock object. The best place for the initialization is in viewDidLoad().
override func viewDidLoad() {
super.viewDidLoad()
let api = XMMEnduserApi(apiKey: "API-KEY")
contentBlocks = XMMContentBlocks(tableView: tableView,
api: api)
}
XMMContentBlocks and UITableView
With the XMMContentBlocks class you do not need to worry how your tableView gets handled anymore. With setting the tableViews datasource to contentBlocks dataSource, the XMMContentBlocks class will handle all dataSource functions automatically for you.
tableView.dataSource = contentBlocks
For handling the click action of an UITableViewCell, just set the tableView delegate to self and implement the didSelectRow function of the UITableView. To react to the specific content block click action you have to call didSelectRowAt in the UITableView datasource function.
extension ContentViewController : UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// Extends tableView didSelectRowAtIndexPath function
// Checks automatically contentBlockType and handles click event for image, video, link, etc.
contentBlocks?.tableView(tableView, didSelectRowAt: indexPath)
}
}
Also set the XMMContentBlocks delegate to self for handling XMMContentBlock blockType "6".
contentBlocks.delegate = self
Now you just have to implement the XMMContentBlocksDelegate in your UIViewController.
extension ContentViewController : XMMContentBlocksDelegate {
func didClickContentBlock(_ contentID: String!) {
// handles contentBlock click action, if contentBlock type is 6 (Type = ContentBlock).
}
}
Lifecycle
To show content in the UITableView you have to call contentBlocks.viewWillAppear() in the UIViewControllers viewWillAppear function. After calling this line, XMMContentBlocks is able to show any content.
override func viewWillAppear(_ animated: Bool) {
contentBlocks?.viewWillAppear()
}
When the UIViewController calls the viewWillDisappear function, also call contentBlocks.viewWillDisappear(). This will ensure that all observers will be removed and every played sound will be stoped.
override func viewWillDisappear(_ animated: Bool) {
contentBlocks?.viewWillDisappear()
}
Display content with XMMContentBlocks
There are two way to display the a content. With or without a header. If you want to show content with the header, just call the displayContent(content) function of XMMContentBlocks.
self.contentBlocks.display(self.content)
To display a content without the header you have to call the display(content, addHeader) function
self.contentBlocks.display(self.content, addHeader: false)
When you are not displaying the header, the contents title and contentsDescription will not be shown on the top of the UIViewController.
Custom Style
You are also be able to change the XMMStyle by calling the style function of XMMContentBlocks.
contentBlocks.style = self.style;
Enable Playstore links
Per default we hide Windows and Playstore app links. To display them just set showAllStoreLinks to true
self.contentBlocks.showAllStoreLinks = true;
Change the fontSize
Per default we set the font size to .NormalFontSize in all of our UI components. If you want to override call updateFontSize() and choose between three different font sizes.
Update the font size with updateFontSize(to: TextFontSize)
self.contentBlocks.updateFontSize(to: .BigFontSize) //.BigFontSize, .BiggerFontSize, .NormalFontSize