Manage a configuration
Load a configuration
To load a configuration file into the SDK, PGCentralManager
provides PGConfigurationManager
property with loadConfigurationFile
method that can be invoked. The method will extract all the configuration information and configuration profiles and save it locally.
The method accepts configurationPath
and completionHandler
parameters, in case the request fails, an Error object will be returned via the completion handler block. If successfully loaded, the method will use the default profile as an active. After the next connection is established, the active profile will be applied to a device.
- (void)loadConfigurationFileAtPath:(nullable NSString *)configurationPath completionHandler:(void (^_Nonnull)(NSError * _Nullable error))completionHandler;
func loadConfigurationFile(atPath configurationPath: String?, completionHandler: @escaping (Error?) -> Void)
Delete a configuration
The already loaded configuration can be deleted by invoking PGConfigurationManager
deleteLoadedConfigurations
method. The method will delete all the configuration information and profiles. The method accepts completionHandler
parameter and if it fails, the error object will be returned via a completion handler block.
- (void)deleteLoadedConfigurationsWithCompletionHandler:(void (^_Nonnull)(NSError * _Nullable error))completionHandler;
func deleteLoadedConfigurations(completionHandler: @escaping (Error?) -> Void)
Get the profiles list
To get the list of all previously loaded profiles PGConfigurationManager
getAllConfigurationProfiles
method can be used. The method accepts completionHandler
parameter and will return an array with PGConfigurationProfile
objects via the completion handler block. In case no object was previously loaded, an empty array will be returned.
- (void)getAllConfigurationProfilesWithCompletionHandler:(void (^_Nonnull)(NSArray<PGConfigurationProfile *> * _Nonnull configurationProfiles))completionHandler;
func getAllConfigurationProfiles(completionHandler: @escaping ([PGConfigurationProfile]) -> Void)
Activate a profile
Once the list of available configuration profiles is retrieved, the profile can be set as active using PGConfigurationManager
changeActiveProfile
method. The method will store the flag locally and, if the device is connected, will apply the configuration profile to a connected device. In case that device is not connected, an active profile will be applied on the next connection.
The method accepts profileCommand
, initialized with the PGConfigurationProfile
and completionHandler
parameters. The error parameter will only be returned via the completion handler if the method fails to set the local flag. The result, if the active profile is applied to a device, will be returned via didSetConfigurationProfile
and didFailToSetConfigurationProfile
delegate method of PGConfigurationManagerDelegate
.
- (void)changeActiveProfile:(nonnull PGCommand *)profileCommand completionHandler:(void (^_Nonnull)(NSError * _Nullable error))completionHandler;
func changeActiveProfile(_ profileCommand: PGCommand, completionHandler: @escaping (Error?) -> Void)
Retrieve the active profile
The currently active profile can be retrieved via the getActiveConfigurationProfile
method of PGConfigurationManager
. The active profile is the profile that will be applied to a scanner on the next successful connection. The method accepts completionHandler
as a parameter. The active profile will be returned via the completion handler block, if available, otherwise nil will be returned.
- (void)getActiveConfigurationProfileWithCompletionHandler:(void (^_Nonnull)(PGConfigurationProfile * _Nullable activeProfile))completionHandler;
func getActiveConfigurationProfile(completionHandler: @escaping (PGConfigurationProfile?) -> Void)
Retrieve the scanner profile set result
To receive a result if the configuration profile is successfully set on a connected device, set the delegate property to PGConfigurationManager
and PGConfigurationManagerDelegate
didSetConfigurationProfile
method will be invoked. The active configuration profile will be set after each successful connection with a scanner or by calling the changeActiveProfile
method while the device is connected.
- (void)peripheral:(nonnull PGPeripheral *)peripheral didSetConfigurationProfile:(nonnull PGConfigurationProfile *)activeProfile;
func peripheral(_ peripheral: PGPeripheral, didSetConfigurationProfile activeProfile: PGConfigurationProfile)
In case a request to apply the configuration profile failed, PGConfigurationManagerDelegate didFailToSetConfigurationProfile
method will be invoked.
- (void)peripheral:(nullable PGPeripheral *)peripheral didFailToSetConfigurationProfile:(nullable PGConfigurationProfile *)activeProfile error:(nullable NSError *)error;
func peripheral(_ peripheral: PGPeripheral?, didFailToSetConfigurationProfile activeProfile: PGConfigurationProfile?, error: Error?)