Ticket T224565
Visible to All Users

How to get nsUserDefaults values in a DevExtreme application on iOS

created 10 years ago

I followed the directions in
http://js.devexpress.com/Documentation/Howto/VS_Integration/Packaging/#Set_Required_Plugins

I have included the following plugin.
https://github.com/apla/me.apla.cordova.app-preferences/

I have created a template and built the application.
All seems well.

I am not able to get the values from the nsUserDefaults on the device.
This is sent down via AirWatch MDM server.
How are we supposed to be able to test/get these values as we are not able to debug in the simulator?
You reference it in the following support link.
https://www.devexpress.com/Support/Center/Question/Details/Q570855

Thanks,
Jay

Answers approved by DevExpress Support

created 10 years ago

Hello Jay
To check if it is possible to get nsUserDefaults values, you need to install your application on a real device and call the 'Fetch' method.
I have created a simple template application and project to demonstrate this.

Thanks, Vlad K

    Other Answers

    created 10 years ago (modified 10 years ago)

    Here is what AirWatch  sent me…
     This worked when I changed the retrieve values to dict …

    Summary of Issue
    •Customer would like to know how to pull application configuration data from the console.

    The following was forwarded to me by an engineer on our Applications Team:

    The variable needs to be included in a specific part of the code for AirWatch to be able to send configuration. That specific part of the code is called NSDictionary for iOS & for the Android platform please refer to the notes outlined below (more details for the iOS platform is included below as well).

    For the Apple device platform:

    Enable Send Application Configuration(iOS 7+ only) to send application configurations to iOS devices. This feature allows you to automatically configure managed applications. Users do not have to manually configure these specified values in the application. Enter the configuration values as unique keys into the appropriate fields. Supported entries for key/value pairs are String, Number, Boolean and Date. You can also use Lookup Values when entering the application configurations. Your internal app has to be developed in such a way to support these functionality.

    Example 1:

    You can test out the following code to the iOS application that you're developing:

    We can push down the UDID as application configuration in one of the variables (configuration key) of the app that is already in the app's code. Following is the process we can use.

    In the app's code, we can put to use:
    NSDictionary *dict = [[NSUserDefaults standardUserDefaults] dictionaryForKey:@"com.apple.configuration.managed"];
    NSString *UDID = dict[@"UDIDKey"];

    In the above code, we created a configuration key 'UDIDKey' and we will pass the UDID value from AirWatch into this configuration key variable.

    Example 2:

    The following code snippet example is used to pass UDID collected to JavaScript:
    NSDictionary *dict = [[NSUserDefaults standardUserDefaults]
    dictionaryForKey:@"com.apple.configuration.managed"];
    NSString *UDID = dict[@"UDIDKey"];

    NSDictionary *namesDict = @{@"uDID": UDID };
    NSError *error;
    NSData *uDIDData = [NSJSONSerialization dataWithJSONObject:namesDict
    options:0
    error:&error];
    NSString *uDIDJSON = [ [NSString alloc] initWithData:uDIDData
    encoding:
    NSUTF8StringEncoding] ;
    NSString *jsCommand = [NSString stringWithFormat:@"setUDID(%@)",
    uDIDJSON];
    [self.webView stringByEvaluatingJavaScriptFromString:jsCommand];

    For the Android device platform:

    On Android there is also no native MDM command for configuring applications. To provide the same capability on Android, the AirWatch MDM agent will facilitate the application configuration using a broadcast intent. When the app is published from the AirWatch console, the AirWatch MDM agent will receive the managed app settings. Once received, the MDM app will listen for the app installation event to detect when the managed app is installed. As soon as the managed app is installed, the AirWatch MDM Agent will broadcast the intent to the managed app. As long the managed app is modified with the following, the app will receive notification of enrollment state and configuration information upon receiving the broadcast intents.

    AndroidManifest.xml
    <receiver android:name="app.package.namespace.ManagedAppInfoReceiver">
    <intent-filter>
    <action android:name="com.airwatch.android.MANAGEMENT_STATUS_ACTION"/>
    <action android:name="com.airwatch.android.MANAGEMENT_CONFIG_ACTION"/>
    </intent-filter>
    </receiver>

    ManagedAppInfoReceiver.java
    /**
    * Copyright © 2014 AirWatch, LLC All rights reserved.
    * This product is protected by copyright and intellectual property laws in the United States and other countries as well as by international treaties.
    * AirWatch products may be covered by one or more patents listed at http://www.vmware.com/go/patents.
    */

    public abstract class ManagedAppInfoReceiver extends BroadcastReceiver {

    protected static final String MANAGEMENT_STATUS_CHANGED = "management_status_change";
    protected static final String MANAGED_CONFIGURATION = "managed_configuration";
    protected static final String MGMT_STATUS_ACTION = "com.airwatch.android.MANAGEMENT_STATUS_ACTION";
    protected static final String MGMT_CONFIG_ACTION = "com.airwatch.android.MANAGEMENT_CONFIG_ACTION";

    /* (non-Javadoc)
    * @see android.content.BroadcastReceiver#onReceive(android.content.Context, android.content.Intent)
    */
    @Override
    public void onReceive(Context ctx, Intent intent) {
    if(intent.getAction().contentEquals(MGMT_CONFIG_ACTION)){
    handleManagementConfiguration(ctx, intent.getStringExtra(MANAGED_CONFIGURATION));
    } else if(intent.getAction().contentEquals(MGMT_STATUS_ACTION)){
    handleManagementStatusChanged(ctx, intent.getBooleanExtra(MANAGEMENT_STATUS_CHANGED, false));
    }
    }

    /**
    Implement in app to define behavior on receipt of configuration data
    @param ctx - The Application context.
    *@param json - The Json string containing the configuration data.
    */
    protected void handleManagementConfiguration(Context ctx, String json){
    //App specific implementation
    }
    /
    *Implement in app to define behavior on receipt of configuration data
    *@param ctx - The Application context.
    *@param state - The current management state of the device. true for managed, false for unmanaged.
    * True will only be broadcast on new enrollments
    * False will only be broadcast on unenrollments.
    */
    protected void handleManagementStatusChanged(Context ctx, boolean state){
    //App specific implementation
    }

    }

      Comments (2)
      DevExpress Support Team 10 years ago

        Jay,

        Would you please clarify whether or not the issue is resolved?

          Hi Jay,
          I am facing a similar problems as yours.
          Are you developing a phonegap/cordova(hybrid) application?
          When retrieving app configuration value from Airwatch MDM, do you need to implement native android/ios functions as mentioned above? Or just fetchinf the value by the cordova plugin?

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.