CoreWLAN commitConfiguration doesn't save config but returns empty error

Hello,

I'm trying to write a simple program which should be able to set wireless profiles. I'm using commitConfiguration function of CWInterface (https://developer.apple.com/documentation/corewlan/cwinterface/1426430-commitconfiguration?language=objc) in order to set the profile and then call CWKeychainSetWiFiPassword to set the corresponding password. However when I try to save the profile using commmitConfiguration, the function returns FALSE and the NSLog of error returns null. The program I'm writing must use wxWidgets library so it's compiled outside Xcode and it's also coded on both C++ and Objective C. I'm currently using CMake to automate the build process.

Here there is the snippet of code:

NSArray<CWInterface*>* interfaces = wifiClient.interfaces;
for(int i = 0; i < interfaces.count; i++){
        NSError* configError = nil;
        CWMutableConfiguration* configCopy = [[CWMutableConfiguration alloc] initWithConfiguration:interfaces[i].configuration];
        NSOrderedSet<CWNetworkProfile *>* networkProfiles = configCopy.networkProfiles;
        NSMutableOrderedSet<CWNetworkProfile*> *networkProfilesCopy = networkProfiles.mutableCopy;
        CWMutableNetworkProfile* networkProfile = [[CWMutableNetworkProfile alloc] init];
        NSString* name = [[NSString alloc]  initWithBytes: name
                                            length: strlen(name)
                                            encoding: NSUTF8StringEncoding];
        NSString* password = [[NSString alloc]  initWithBytes: password
                                                length: strlen(password)
                                                encoding: NSUTF8StringEncoding];
        NSInteger networkProfileIndex;                              
        OSStatus keychainStatus;
        bool configStatus;
        //... fragment of code which sets the security algorithm for the network omitted...
        networkProfile.ssidData = [name dataUsingEncoding:NSUTF8StringEncoding];
        networkProfileIndex = [networkProfilesCopy indexOfObject:networkProfile];
        //If network profile already exist, replace it without changing its position in the ordered set
        if(networkProfileIndex == NSNotFound){
            [networkProfilesCopy addObject:networkProfile];
        }else{
            [networkProfilesCopy replaceObjectAtIndex:networkProfileIndex withObject:networkProfile];
        }
        [configCopy setNetworkProfiles:networkProfilesCopy];
        configStatus = [interfaces[i] commitConfiguration:configCopy authorization:nil error:&configError];
        if(configStatus){
            keychainStatus = CWKeychainSetWiFiPassword(kCWKeychainDomainUser, networkProfile.ssidData, password);
           return keychainStatus;
        }else{
           NSLog(@" error => %@ ", [configError userInfo]);
          return false;
        }
    }

The strange thing I noticed is that if I run the program using sudo, commitConfiguration seems to work.

Thanks in advance