Load pages - xamoom/xamoom-ios-sdk GitHub Wiki

In this guide you will learn about all the different ways of loading pages like getting a page with a given id, by tags, by location or beacon. All following API calls are defined in XMMEnduserApi.

It does not matter what call you are using, there are a few important parameters which you can use in all of them.

Reason

This parameter specifies why a content will be loaded and is primary used to get better statistics on the xamoom dashboard. Possible use cases are, when a content is loaded after clicking a notification (opening rate) or if a content will be show because a user is near an iBeacon. It is very important to always send the right reason in the right case. All possible reasons are listed in XMMReasons

Options

This is currently only used to specify if the call should write statistics or not. See -> XMMContentOption.

Content by id

Will return the content item with the given Id. Since SDK version 3.11.2 you are able to set a password for password protected contents. The password field in this call is optional and can be nil.

api.content(withID: "contentId", password: nil, completion: { (content, error, passwordRequired) in
   if let error = error {
      print("Error \(error)")
   } else if let content = content {
      print("Content: \(content)")
   }
})

Content by location identifier

Another way to get a content is to call the contentWithLocationIdentifier function of XMMEnduserApi. You will call this function after scanning a QR code or a NFC Tag. How to get the location identifier in this two cases, is described here. Since SDK version 3.11.2 you are able to set a password for password protected contents. The password field in this call is optional and can be nil.

api.content(withLocationIdentifier: "location-identifier", password: nil, completion: { (content, error, passwordRequired) in
if let error = error {
      print("Error \(error)")
   } else if let content = content {
      print("Content: \(content)")
   }
})

Content by Beacon Id

One SDK function is to load a content for a ranged beacon. All you need is your beacon's MAJOR ID and the MINOR ID.

api.content(withBeaconMajor: 0, minor: 0, completion: { (content, error, passwordRequired) in
if let error = error {
      print("Error \(error)")
   } else if let content = content {
      print("Content: \(content)")
   }
})

Query Content

The SDK also implements calls for loading a list of content items. The result of these calls includes an array of XMMContent, a flag "hasMore", a String "cursor" and an Error. All of these fields are optional and can be null.

Filter

When you are calling a function, for loading an array of content items you are also able to filter the result with setting the filter parameter. For this you are using the XMMFilter class. There you can set up to five different filter options. These options are:

  • name (Fulltext Query)
  • Array of tags (treated as OR)
  • from Date (Event Package)
  • to Date (Event Package)
  • A Spot Id (Event Package)

Sort

You can define the ordering, ascending or decending. You can also specify the attribute that should be used to sort the list. All available sorting options are listed in XMMOptions.

Content items by tags

In this example we load all content items that have the tag "start".

api.contents(withTags: ["start"], pageSize: 100, cursor: nil, sort: .init(rawValue: 0), filter: nil, completion: { (contents, hasMore, cursor, error) in
   if let error = error {
      print("Error: \(error)")
   } else if let contents = contents {
      print("Number of contents: \(contents.count)")
   }
})

Content items by name

You can also load content items with a String as part of their name. This example will return content items with "brand name" as part of their name.

api.contents(withName: "brand name", pageSize: 100, cursor: nil, sort: .init(rawValue: 0), completion: { (contents, hasMore, cursor, error) in
   if let error = error {
      print("Error: \(error)")
   } else if let contents = contents {
      print("Number of contents: \(contents.count)")
   }
})

Content items by location

If you need to get all content items, bound to Spots within 40 meter around a given location, you can call this function of XMMEnduserApi. You only have to set the location and will get an array of XMMContent around the user's location.

api.contents(with: userLocation, pageSize: 100, cursor: nil, sort: .init(rawValue: 0), completion:{ (contents, hasMore, cursor, error) in
   if let error = error {
      print("Error: \(error)")
   } else if let contents = contents {
      print("Number of contents: \(contents.count)")
   }
})

Content items within dates

If the "event package" is activated, you can specifiy from and to dates on every content item in ther CMS and query for them by these dates. To do this you set the fromDate and toDate parameter of the query and you will get all content items in this range. You have to set at least one of these dates to make the call work. The fromDate defines the minimum date and the toDate the maximum date of the result set. It's also possible to set a specific spotId you want to filter for, which is also part of the "event package" feature.

api.contents(from: Date(), to: Date(), relatedSpot: nil, pageSize: 100, cursor: nil, sort: .init(rawValue: 0), completion:{ (contents, hasMore, cursor, error) in
   if let error = error {
      print("Error: \(error)")
   } else if let contents = contents {
      print("Number of contents: \(contents.count)")
   }
})

Recommended Content

xamoom also offers personal recommendations for single users. To make this work it is important that you understand how Ephemeral Id works and that you also always send the right content reason and all calls. The result of this call changes based on the user's interaction with content and also depending on date and time.

api.contentRecommendations(completion: { (contents, hasMore, cursor, error) in
   if let error = error {
      print("Error: \(error)")
   } else if let contents = contents {
      print("Number of contents: \(contents.count)")
   }
})

This call will at most return 10 items and paging as well as sorting is ignored, since it is sorted by how likely it is that this user is interested in a certain item.

Password Protection

It is also possible to set a password for a page in our CMS. To handle this case, we extended the completionBlocks for some XMMEnduserApi calls. They are now containing a Content, an Error and a BOOL flag. For a more detailed description how the password handling works, read in the Password Protection page.

Next Step