Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-11399

iOS: Ti.App.Properties.setObject cannot save object with null values in it

    Details

      Description

      Problem

      When trying to set an object in the client side properties by using "Ti.App.Properties.setObject()", the object that contains a key that has a null value it won't be saved.

      Actual result

      When replacing the 'something' -key with a non-null value, the property however CAN be saved.

      Repro sequence

      var win = Ti.UI.createWindow({ backgroundColor: 'white' });
         
      var objectWithNullValue = {
        expires_at: 1347623585,
        value: {
          something: null
        }
      };
       
      var objectWithoutNullValue = {
        expires_at: 1347623585,
        value: {
          something: 'value'
        }
      };
        
      Ti.App.Properties.setObject('Object1', objectWithNullValue);
      Ti.App.Properties.setObject('Object2', objectWithoutNullValue); 
       
       
      Ti.API.info('----- object 1 -----');
      Ti.API.info(Ti.App.Properties.getObject('Object1'));
      Ti.API.info('Type of Object1: ' + typeof Ti.App.Properties.getObject('Object1'));
      Ti.API.info('Value of Object1: ' + Ti.App.Properties.getObject('Object1'));
      Ti.API.info('Stringified value of Object1: ' + JSON.stringify(Ti.App.Properties.getObject('Object1')));
       
      Ti.API.info('----- object 2 -----');
      Ti.API.info(Ti.App.Properties.getObject('Object2'));
      Ti.API.info('Type of Object2: ' + typeof Ti.App.Properties.getObject('Object2'));
      Ti.API.info('Value of Object2: ' + Ti.App.Properties.getObject('Object2'));
      Ti.API.info('Stringified value of Object2: ' + JSON.stringify(Ti.App.Properties.getObject('Object2')));
       
      win.open();
       
      Ti.API.info('----- My name -----');
      Ti.App.Properties.setObject( "object" , { name: "eduardo" , lastName: null } );
      Ti.API.info(Ti.App.Properties.getObject('object'));
      

      iOS Console output

      [INFO] Detected third-party module: ti.location/1.0
      [INFO] Titanium SDK version: 3.0.0 (10/08/12 21:09 7bf73ff)
      [INFO] iPhone Device family: universal
      [INFO] iPhone SDK version: 5.1
      [INFO] iPhone simulated device: iphone
      [WARN] The project seems to be having custom info.plist which does not contain  the `CFBundleShortVersionString` key
      [INFO] Generating the missing `CFBundleShortVersionString` key
      [INFO] Minimum iOS version: 4.0 Linked iOS Version 5.1
      [INFO] Launching application in Simulator
      [INFO] Launched application in Simulator (5.11 seconds)
      [INFO] Application started
      [INFO] 1BestPractices/1.0 (3.0.0.v20121008210903.7bf73ff)
      [INFO] ----- object 1 -----
      [INFO] {
          value =     {
          };
      }
      [INFO] Type of Object1: object
      [INFO] Value of Object1: [object Object]
      [INFO] Stringified value of Object1: {"value":{}}
      [INFO] ----- object 2 -----
      [INFO] {
          "expires_at" = 1347623585;
          value =     {
              something = value;
          };
      }
      [INFO] Type of Object2: object
      [INFO] Value of Object2: [object Object]
      [INFO] Stringified value of Object2: {"expires_at":1347623585,"value":{"something":"value"}}
      [INFO] ----- My name -----
      2012-10-11 17:12:48.872 1BestPractices[6080:1a903] *** -[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '{
          lastName = "<null>";
          name = eduardo;
      }' of class '__NSCFDictionary'.  Note that dictionaries and arrays in property lists must also contain only property values.
      [INFO] <null>
      

      Android Console logs

      10-11 17:12:29.501: I/TiApplication(3486): (main) [0,0] checkpoint, app created.
      10-11 17:12:29.540: I/TiApplication(3486): (main) [37,37] Titanium 3.0.0 (2012/10/08 21:09 7bf73ff)
      10-11 17:12:29.704: I/TiDbHelper(3486): (main) [171,208] No value in database for platform key: 'unique_machine_id' returning supplied default ''
      10-11 17:12:29.712: I/TiDbHelper(3486): (main) [4,212] No value in database for platform key: 'hardware_machine_id' returning supplied default ''
      10-11 17:12:29.766: I/TiApplication(3486): (main) [58,270] Titanium Javascript runtime: v8
      10-11 17:12:29.774: D/dalvikvm(3486): Trying to load lib /data/data/com.appc.test/lib/libstlport_shared.so 0x4051ccb8
      10-11 17:12:29.774: D/dalvikvm(3486): Added shared lib /data/data/com.appc.test/lib/libstlport_shared.so 0x4051ccb8
      10-11 17:12:29.774: D/dalvikvm(3486): No JNI_OnLoad found in /data/data/com.appc.test/lib/libstlport_shared.so 0x4051ccb8, skipping init
      10-11 17:12:29.774: D/dalvikvm(3486): Trying to load lib /data/data/com.appc.test/lib/libkroll-v8.so 0x4051ccb8
      10-11 17:12:29.790: D/dalvikvm(3486): Added shared lib /data/data/com.appc.test/lib/libkroll-v8.so 0x4051ccb8
      10-11 17:12:29.821: I/TiRootActivity(3486): (main) [0,0] checkpoint, on root activity create, savedInstanceState: null
      10-11 17:12:29.852: I/TiAnalyticsDb(3486): (main) [35,35] Upgrading Database from 1 to 4
      10-11 17:12:30.016: E/TiApplication(3486): (KrollRuntimeThread) [159,194] APP PROXY: ti.modules.titanium.app.AppModule@405e3f90
      10-11 17:12:30.094: I/TiAPI(3486):  ----- object 1 -----
      10-11 17:12:30.094: I/TiAPI(3486):  [object Object]
      10-11 17:12:30.094: I/TiAPI(3486):  Type of Object1: object
      10-11 17:12:30.094: I/TiAPI(3486):  Value of Object1: [object Object]
      10-11 17:12:30.094: I/TiAPI(3486):  Stringified value of Object1: {"expires_at":1347623585,"value":{"something":null}}
      10-11 17:12:30.094: I/TiAPI(3486):  ----- object 2 -----
      10-11 17:12:30.094: I/TiAPI(3486):  [object Object]
      10-11 17:12:30.094: I/TiAPI(3486):  Type of Object2: object
      10-11 17:12:30.094: I/TiAPI(3486):  Value of Object2: [object Object]
      10-11 17:12:30.094: I/TiAPI(3486):  Stringified value of Object2: {"expires_at":1347623585,"value":{"something":"value"}}
      10-11 17:12:30.110: D/LSAPP_TelMon(783): onCellTowerChanged CDMA :: {"NetTyp":"CDMA","BaseStnLat":"2147483647","NetOp":"33404","BaseStnId":"623","BaseStnLng":"2147483647","CntryISO":"mx","NetId":"0","SysId":"24587"}
      10-11 17:12:30.126: D/LSAPP_TelMon(783): Telmon : celltower changed...new cell...clear bouncing cells upon new cell and no pending timer 
      10-11 17:12:30.126: D/LSAPP_TelMon(783): emptyBouncingCells :: 
      10-11 17:12:30.173: I/TiAPI(3486):  ----- My name -----
      10-11 17:12:30.180: I/TiAPI(3486):  [object Object]
      

      Associated Community thread

      http://developer.appcelerator.com/question/139212/sdk-210-propertiessetobject-error-when-setting-null

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                vduggal Vishal Duggal (Inactive)
                Reporter:
                gnoesiboe Gijs Nieuwenhuis
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-14657
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Integration