Password Protection - xamoom/xamoom-ios-sdk GitHub Wiki

Since SDK version 3.11.2 it is possible to handle password protected pages with XMMEnduserApi calls. To use password protection, you have to set one for a specific page in the CMS. The password logic works automatically when loading a page with an ID or with a locationIdentifier. To send the password with the page request we extended these calls with the optional "password" field.

XMMEnduserApi functions

As mentioned all functions handles the password protection for their own, when loading a single page per ID or locationIdentifier.

Usage

First of all you should request every content with nil as password, because if there was a password set, the completion's third parameter will return true.

As mentioned earlier the XMMEnduserApi functions handle this automatically and will return true if a password is required and false if not.

api.content(withID: "contentId", password: nil, completion: { (content, error, passwordRequired) in
      if let error = error {
        // If you entered the password wrong for three times you will end up here.
        print("Error \(error)")
      } else if passwordRequired {
        // If a password was set for this content you will end up here.
        // Make a new api call here and set the required password, e.g. UIAlertController
      } else if let content = content {
        print("Content: \(content)")
      }
})

This functions also handle the amount of tries for its own. You have three tries to send the correct password and every time the password was wrong the passwordRequired flag is false. But if all three tries are wrong you have a 15 minute cool down time for this page.

Handle wrong password enters

If you entered the password wrong for three times, the SDK will automatically load a page with x-forbidden as tag. If no page was found with this tag, the completion returns an error with error code 92. So you can handle this error for your own.

api.content(withID: "contentId", password: nil, completion: { (content, error, passwordRequired) in
      if let error = error {
        let e = error as NSError
        if e.code == 92 {
          // Handle three times wrong password
        }
        print("Error \(error)")
      } else if passwordRequired {
        // If a password was set for this content you will end up here.
        // Make a new api call here and set the required password, e.g. UIAlertController
      } else if let content = content {
        print("Content: \(content)")
      }
})