Dynamic Type & iOS Simulator: how to set a value?

I want to write my user interface tests so that they test all seven states of a dynamic type, from the smallest to the largest. How can I do it?

Can I set the environment variable for the simulator in my Schema and then just make different schemes?

Or can I set a dynamic variable of type programmatically in my test?

I would prefer not to create a DynamicTypeController and then get it to say what type it is, because I would risk using it for some elements, and then I shouldn't test the behavior correctly.

Greetings

Nick

+6
source share
1 answer

I apologize for the incompleteness of this answer, but it is too long for a comment and there will be no code formatting.

Short answer: this is not supported: https://forums.developer.apple.com/thread/21503 , but it probably requires a radar.

Longer answer: you could hack something. The dynamic type setting in the simulator is available on your file system at: ~/Library/Developer/CoreSimulator/Devices/<device identifier>/data/Library/Preferences/com.apple.UIKit.plist . You can programmatically get the path to the simulator file system from within XCTest using:

  let environment = NSProcessInfo.processInfo().environment if let resourcesDir = environment[ "SIMULATOR_SHARED_RESOURCES_DIRECTORY" ] { print( "-- Simulator Shared Resources Directory: \(resourcesDir)" ) let dictionary = NSMutableDictionary( contentsOfFile: "\(resourcesDir)/data/Library/Preferences/com.apple.UIKit.plist" )! print( "Dictionary: \(dictionary)" ) } 

However, the test is isolated from the simulator directory, so you cannot open or change settings. This piece of code does not work when trying to deploy a dictionary. I also never tried this with Xcode Server.

You can change the plist using a shell script as follows: plutil -replace UIPreferredContentSizeCategoryName -string UICTContentSizeCategoryAccessibilityXXXL com.apple.UIKit.plist . The simulator must be restarted after changing the file so that it cannot fly in a collaborative build environment. Unfortunately, the path to the simulator file system is not available for Pre-action scripts in Xcode. You can change the setting for all simulators, but again, it may not fly in the general build environment.

At the end of the day, you might be better off creating your DynamicTypeController and adding some process so that no one uses UIApplication.preferredContentSizeCategory .

All of this has been tested using Xcode 7.1 (7B91b).

+3
source

All Articles