Settings
SAPcpmsSettings
Reads, stores and deletes settings that are centrally maintained on SAP Mobile Services.
Tip: See Storage Service for information about and direct links to commonly performed SAP Mobile Services configuration tasks that support SAP BTP SDK for iOS applications.
Usage
Setting up SAPcpmsSettings
Use the SAPFoundation framework’s SAPcpmsSettings
component implementation.
Create an SAPURLSession
and add it to one of the initializers.
a.) Convenience initializer
The recommended initializer is using the SAPcpmsSettingsParameters
as a parameter:
var urlSession = SAPURLSession()
let backendURL = URL(string: <#domain#>)!
let settingsParameters = SAPcpmsSettingsParameters(backendURL: backendURL, applicationID: <#appid#>)
let settings = SAPcpmsSettings(sapURLSession: urlSession, settingsParameters: settingsParameters)
b.) Default initializer
The initializer uses different URLs for different target settings. The default settings target is userSettings
.
The userSettingsURL
and deviceSettingsURL
are optional:
var urlSession = SAPURLSession()
let applicationSettingsURL = URL(string: <#complete URL for application settings#>)!
let userSettingsURL = URL(string: <#complete URL for user settings#>)!
let deviceSettingsURL = URL(string: <#complete URL for device settings#>)!
let settings = SAPcpmsSettings(sapURLSession: urlSession, applicationSettingsURL: applicationSettingsURL, userSettingsURL: userSettingsURL, deviceSettingsURL: deviceSettingsURL)
Loading settings
a.) All settings
This sample code demonstrates how to load all settings from SAP Mobile Services:
settings.load { settings, error in
// Evaluate settings
// Handle error properly
}
b.) Only the SAP Mobile Services
This sample code demonstrates how to load only the SAP Mobile Services:
settings.loadSAPcpmsSettings { settings, error in
// Evaluate settings
// Handle error properly
}
c.) Only one specific settings or one part of it
This sample code demonstrates how to load a specific setting. The settingsKeyPath
is appended to the end of the URL to point a particular section in the settings. The settingsKeyPath
is a slash ‘/’ separated URL Path. If it does not contain the path separator, the search begins at the top level. The result can be part of the JSON or a property of the JSON:
settings.load(settingsKeyPath: <#settings key path#>) { settings, error in
// Evaluate settings
// Handle error properly
}
Storing settings
This sample code demonstrates how to create or update settings on SAP Mobile Services.
The settingsKeyPath
can be a slash separated URL path, in which case the slash is set to a different level. All levels are stored. The SettingsTarget
could be: .application
, .user
or .device
:
let settingsDict = [<#key#>: <#value#>]
settings.store(settings: settingsDict, settingsKeyPath: <#settings key path#>, for: <#settings target#>) { error in
// Handle error properly
}
Deleting settings
This sample code demonstrates how to delete settings on SAP Mobile Services.
The settingsKeyPath
can be a slash separated URL path, in which case the slash is set to a different level:
settings.delete(settingsKeyPath: <#settings key path#>) { error in
// Handle error properly
}
Passing logger settings to the Logger
This sample code demonstrates how to load the settings from SAP Mobile Services and pass them to the Logger:
private let logger = Logger.shared(withName: <#logger identifier#>)
settings.load { settings, error in
let sapcpmsLogSettings = try? SAPcpmsLogSettings(sapcpmsSettings: settings)
logger.apply(sapcpmsLogSettings: sapcpmsLogSettings)
}
Parsing the SAP CPms Lock-Wipe policy with the SAPcpmsLockWipePolicy
This sample code demonstrates how to load the settings from SAP Mobile Services and initialize an SAPcpmsLockWipePolicy structure:
settings.load { settings, error in
let sapcpmsLockWipePolicy = try? SAPcpmsLockWipePolicy(sapcpmsSettings: settings)
}
Parsing the SAP CPms Usage policy with the SAPcpmsUsagePolicy
This sample code demonstrates how to load the settings from SAP Mobile Services and initialize an SAPcpmsUsagePolicy structure:
settings.load { settings, error in
let sapcpmsUsagePolicy = try? SAPcpmsUsagePolicy(sapcpmsSettings: settings)
}
Parsing the SAP CPms Network Synchronization policy with the SAPcpmsNetworkSynchronizationPolicy
This sample code demonstrates how to load the settings from SAP Mobile Services and initialize an SAPcpmsNetworkSynchronizationPolicy structure:
settings.load { settings, error in
let sapcpmsNetworkSynchronizationPolicy = try? SAPcpmsNetworkSynchronizationPolicy(sapcpmsSettings: settings)
}
Settings component Logger ID
This component uses the following name prefix for logging: ‘SAP.Foundation.Settings’
-
Describes the SAPcpms Lock-Wipe policy structure
See moreDeclaration
Swift
public struct SAPcpmsLockWipePolicy
extension SAPcpmsLockWipePolicy: CustomStringConvertible, CustomDebugStringConvertible
-
Declaration
Swift
extension SAPcpmsLogSettings
-
A settings reading and storing settings JSON from and to SAP Mobile Services. It uses the SAP Mobile Services Store API endpoint for that.
These protocols represent the following JSON payload which is returned by the Settings Exchange API of SAP Mobile Services
{ "mobileservices": { "__metadata": { "writeRoles": ["Administrator"] }, "settingsExchange": { "passwordPolicy": { "passwordPolicyMinLength": "8", "passwordPolicyLowerRequired": "false", "passwordPolicyDefaultPasswordAllowed": "false", "passwordPolicyRetryLimit": "10", "passwordPolicyUpperRequired": "false", "passwordPolicyEnabled": "false", "passwordPolicySpecialRequired": "false", "passwordPolicyExpiresInNDays": "0", "passwordPolicyLockTimeout": "300", "passwordPolicyDigitRequired": "false", "passwordPolicyMinUniqueChars": "0" }, "featureVectorPolicies": { "featureVectorPolicyAllEnabled": "true", "restrictedPolicies": null }, "attestationSettings": { "iOS": { "enabled": true, "enforced": false }, "android": { "enabled": "false", "enforced": "false" } } "logSettings": { "logEntryExpiry": "7", "logLevel": "NONE" } } }, //Custom App-Specific data (structure unknown and defined by app) customAppDefinedConfigs1: { appConfig1: "value1", appConfig2: "value2" }, //Custom App-Specific data (structure unknown and defined by app) customAppDefinedConfigs2: { appConfig1: "value1", appConfig2: "value2" }, }
This sample code demonstrates how to create an SAPcpmsSettings instance:
See morevar urlSession = SAPURLSession() let settingsParameters = SAPcpmsSettingsParameters(backendURL: <#URL only with domain#>, applicationID: <#appid#>) let settings = SAPcpmsSettings(sapURLSession: urlSession, settingsParameters: settingsParameters)
Declaration
Swift
open class SAPcpmsSettings
-
Error types that can throw this framework
See moreDeclaration
Swift
public enum SAPcpmsSettingsError : Error
extension SAPcpmsSettingsError: SAPError
-
Structure to hold SAPcpms settings metadata. E.g. on which host can be found the given application by applicationID. Extra information could be store for the device and user specific settings.
See moreDeclaration
Swift
public struct SAPcpmsSettingsParameters : Codable
extension SAPcpmsSettingsParameters: DiscoveryServiceConfigurable
extension SAPcpmsSettingsParameters: CustomStringConvertible, CustomDebugStringConvertible
-
Describes the SAPcpms Usage policy structure
See moreDeclaration
Swift
public struct SAPcpmsUsagePolicy
extension SAPcpmsUsagePolicy: CustomStringConvertible, CustomDebugStringConvertible
-
Describes the SAPcpms Network Synchronization policy structure
See moreDeclaration
Swift
public struct SAPcpmsNetworkSynchronizationPolicy
extension SAPcpmsNetworkSynchronizationPolicy: CustomStringConvertible, CustomDebugStringConvertible
-
Set of options that determine when to synchronize data
See moreDeclaration
Swift
public struct SAPcpmsNetworkSynchronizationPolicyOptions : OptionSet