简体   繁体   中英

Retrieving Username Through MDM by Configuring Enterprise App Preferences (AirWatch)

I am building a hybrid app with Ionic/Cordova and am using a plugin ( https://github.com/apla/me.apla.cordova.app-preferences ) to retrieve a username value from the Root.plist file contained in Settings.bundle.

I am having difficulty sending this value through AirWatch (MDM Solution) and then properly reading it during runtime. I am using the Application Configuration setting while deploying the app as shown below:

In the AirWatch Console:

应用配置

Root.plist Source Code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>PreferenceSpecifiers</key>
    <array>
        <dict>
            <key>Key</key>
            <string>AWUsername</string>
            <key>DefaultValue</key>
            <dict>
                <key>Value</key>
                <string>Test</string>
            </dict>
        </dict>
    </array>
</dict>
</plist>

JS

var retrieveUser = function () {
      var prefs = window.plugins.appPreferences;
      //prefs.fetch (ok, fail, 'dict', 'key');
      prefs.fetch(prefReadSucess, prefReadFailed, 'AWUsername', 'AWUsername');

      function prefReadSucess(value) {
          console.log("User: " + value);
          DataTransfer.getUser(value);
      }

      function prefReadFailed(error) {
          console.log("Error: " + error);
          DataTransfer.getUser("ANONYMOUS");
      }
   };

    retrieveUser();

With the code mentioned above, the result is that I get the value "Test" where the username should be populating. I have tried numerous variations in the Root.plist file but cannot seem to pair the AirWatch App Config Key to the key located in the Root.plist file. Help would be greatly appreciated! Please let me know what I am doing wrong and/or how I can fix this. Thanks!

SOLUTION

After several attempts I have reached a working version. It seems to require that the key is named "com.apple.configuration.managed" Replacing this value has not worked so far. Anyways, here's how I did it:

AirWatch Console

Configuration Key: com.apple.configuration.managed
Value Type: String
Configuration Value: {DisplayName}

Root.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>PreferenceSpecifiers</key>
    <array>
        <dict>
            <key>Key</key>
            <string>com.apple.configuration.managed</string>
            <key>DefaultValue</key>
            <dict>
                <key>Value</key>
                <string>ANONYMOUS</string>
            </dict>
        </dict>
    </array>
</dict>
</plist>

JS

var retrieveUser = function () {
      var prefs = window.plugins.appPreferences;
      //prefs.fetch (ok, fail, 'dict', 'key');
      prefs.fetch(prefReadSucess, prefReadFailed, 'com.apple.configuration.managed', 'com.apple.configuration.managed');

      function prefReadSucess(value) {
          console.log("User: " + value);
          DataTransfer.getUser(value);
      }

      function prefReadFailed(error) {
          console.log("Error: " + error);
          DataTransfer.getUser("ANONYMOUS");
      }
    };

    retrieveUser();

Hope that helps anyone seeking a solution!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM