REGRESSION UIAApplication.setPreferencesValueForKey() does not work iOS 8 GM on devices

Originator:joshuajmoody
Number:rdar://18310683 Date Originated:11-Sep-2014 10:51 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6 GM
Classification:Serious Bug Reproducible:Always
 
Summary:
If I set a value with UIAApplication.setPreferencesValueForKey, I expect to be able to see that value appear in my NSUserDefaults.

> setPreferencesValueForKey
>> Sets the value of a specified app user preference.

This works in iOS 6 and iOS 7.

It works on the iOS 6 - 8 Simulators.

It does not work on iOS GM.

Possibly related to:

* rdar://18296714
* rdar://17821465
* rdar://15530604
* rdar://18310483

Steps to Reproduce:
### To Reproduce

**Requires**

* iOS 8 GM device
* The source code of an iOS app.
* Instruments 6 GM

1.  In the UIApplicationDelegete application:didFinishLaunchingWithOptions: method add the following code to log the NSUserDefaults

```
  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  [defaults synchronize];
  NSDictionary *dictionary = [defaults dictionaryRepresentation];
  NSData *data = [NSJSONSerialization dataWithJSONObject:dictionary
                                                 options:NSJSONWritingPrettyPrinted
                                                   error:nil];
  NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

  NSLog(@"defaults = %@", string);
```
2. Launch Instruments 6 GM and select the Automation template.
3. Target the iOS 8 GM device and select an app to target.
4. Execute this script

```
var target = UIATarget.localTarget();

// This value never appears in NSUserDefaults standardUserDefaults
target.frontMostApp().setPreferencesValueForKey("value", "com.example.set-in-uia-automation")
var valueSetByScript  = target.frontMostApp().preferencesValueForKey("com.example.set-in-uia-automation")
if (valueSetByScript == "value") {
    UIALogger.logPass("The value I set in UIAutomation was '" + valueSetByScript + "'");
} else {
    UIALogger.logFail("Expected to see 'value' but found '" + valueSetByScript + "'");
}
```

5. Launch the app again, either from Xcode or Instruments and inspect the Console log.

Expected Results:
### Expected

I expected to see the key/value pair from the setPreferencesValueForKey in the console log.


Actual Results:
### Found

* Works on iOS 6 - 8 on simulators.
* Works on iOS 6 - 7 on devices.

On iOS 8 GM, the key/value pair does not appear in NSUserDefaults.


Version:
OS X 10.9.4 (13E28)
Xcode6 GM
instruments, version 6.0 (56156)
iOS 8 GM

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!