Show pages - xamoom/xamoom-ios-sdk GitHub Wiki
For showing a page properly you need to know how to load a page and how API Calls work in the SDK, if you have not read Load pages and API Calls you should do this before going on.
Every content object contains contentBlocks. This is an array of XMMContentBlock. The XMMContentBlock class can hold any attribute which can be set in the CMS, but the most important attirbute is blockType. In our SDK we implemented a single TableViewCell for each of the available block type. For handling these TableViewCells the XMMContentBlocks class is used. XMMContentBlocks handles the UITableViewDataSource and the UITableViewDelegate and sets the correct XMMContentTableViewCell for each blockType.
Preperations
First of all you have to implement a UITableView in the Controller you want to show a content in. Also you have to create a XMMContentBlocks object.
contentBlocks = XMMContentBlocks(tableView: tableView,
api: api)
After that you will set the contentBlock´s and the tableView´s delegate to self. These delegates will handle any click action for the TableViewCells. Also you have to outsource the UITableViewDelegate functionality to your XMMContentBlocks object.
contentBlocks.delegate = self
tableView.delegate = self
tableView.dataSource = contentBlocks
For understanding how the delegate functions work and how different blokckTypes affect the click behavior, check the didSelectRowAtIndexPath of contentBlocks.
XMMContentBlocksDelegate
The only blockType which works differently than the others, is the blockType 6. For handling this click event you need to implement the XMMContentBlocksDelegate in your Controller.
extension ContentViewController : XMMContentBlocksDelegate {
func didClickContentBlock(_ contentID: String!) {
// handles contentBlock click action, if contentBlock type is 6 (Type = ContentBlock).
}
}
UITableViewDelegate
For handling any other blockType click action, 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)
}
}
viewWillAppear
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()
}
viewWillDisappear
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 stopped.
override func viewWillDisappear(_ animated: Bool) {
contentBlocks?.viewWillDisappear()
}
Show content
After properly setup the XMMContentBlocks class and implementing the delegates the contentBlocks object is ready to show a content. To show a content call displayContent(content) of the XMMContentBlocks class.
self.contentBlocks.display(self.content)
If you do not want to show the contents title and contentsDescription on the top, just call the display(content, addHeader) function.
self.contentBlocks.display(self.content, addHeader: false)
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;
Open URLs in your app
We also implemented the functionality for open urls with a given scheme in a WebView without leaving the app. For this follow this guidelines.
Apple Maps Navigation type
You are also able to set the navigation type for Apple Maps. Apple Maps will automatically be opened when clicking on the "Navigation" Button in XMMMapOverlyView. For setting the navigation type following line is required.
self.contentBlocks.navigationType = 0
Following navigation types are available:
- Walking = 0
- Driving = 1
- Transit = 2
The default navigation type is Walking.
Mapbox Style
Since we are using Mapbox for displaying our Spots, it is also possible to set your custom Mapbox Style. For this you only have to set this string like this.
contentBlocks.mapboxStyle = URL(string: "your-style-srting")
The default mapbox style, when you are not defining your custom style is MAPBOX_STREETS.
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
Customize Contentblocks
You can also customize how ContentBlocks look by following the ContentBlock Customizing guide or just changing the appearance of them.