Monthly Archives: April 2017

iOS and App Transport Security Settings

Some time ago, Apple added a security feature to iOS that requires all domains that an app needs to connect to without HTTPS be white-listed in the info.plist file.

It’s pretty simple, you create a Dictionary object with the name of NSAppTransportSecurity and then add a key with the name NSAllowsArbitraryLoads and the bool value of True.  This will basically bypass the security system and allow your app to read from any website.

The problem coming down the pipe, is they are going to turn this ‘temp’ feature off sometime this year.  When they do, an App using this scheme will not be able to read from a non-HTTPS URL.

To get around this you need to explicitly add domains to your white-list.  Not too hard, but it needs to be done.

In the NSAppTransportSecurity, create another dictionary with the name NSExceptionDomains.  Then create another dictionary for each domain you’ll need access to, with the root domain as the name.  Inside that dictionary, add two items – NSTemporaryExceptionAllowsInsecureHTTPLoads with a bool value of TRUE, and NSIncludesSubdomains also with a bool value of TRUE.

That will let you read from those domains in the future, even when Apple kill NSAllowsArbitraryLoads.

The following is an extract from one of our apps which allows the app to read from purplebuttons.com.

<dict>
<key>purplebuttons.com</key>
<dict>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>

Custom Inspector: Mixing custom drawer and default property drawers

I’ve been playing around with ScriptableObjects and using them to define parameters for my Dialog display gameobject.  In previous instances, I’d just use constant strings and pass them to the function that creates and displays the dialog.  After reading about ScriptableObjects, I decided to give them a shot to build strings for the dialogs.

Everything was great, except for the inspector displaying long strings.  They just get truncated of the right side of the display.  The behavior exhibited by the NGUI UILabel inspector is much better, as any text to long to be displayed in the inspector is wrapped and the field is extended vertically.

I found the NGUI code in UILabelInspector that handles the displaying of strings across multiple lines, and took a copy to use in my own inspector.  Then I realized, with a custom inspector I have to display all the properties myself, and I didn’t want to (a) write a custom display for each property type, and (b) remember to extend the inspector anytime I modified my ScriptableObject class.

The second problem was solved by iterating over the SerializedProperties contained in the SerializedObject, while the first problem was solved by calling EditorGui.PropertyField on SerializedProperties I didn’t want to display myself.

I then added an exception for the ‘Script’ property, to make it non-editable.

This resulted in the code below:

public override void OnInspectorGUI()
{
	serializedObject.Update();
	SerializedProperty sp = serializedObject.GetIterator();
	if (!sp.NextVisible(true))
		sp = null;
	while (sp!=null)
	{
		if (sp.type == "string")
			DrawMultiLineString(sp.name);
		else
		{
			Rect position = EditorGUILayout.GetControlRect(GUILayout.Height(EditorGUI.GetPropertyHeight(sp)));
			if (sp.name == "m_Script")
			{
				EditorGUI.BeginDisabledGroup(true);
				EditorGUI.PropertyField(position, sp, new GUIContent(sp.displayName), true);
				EditorGUI.EndDisabledGroup();
			}
			else
				EditorGUI.PropertyField(position, sp, new GUIContent(sp.displayName), true);
		}
		if (!sp.NextVisible(true))
			sp = null;
	}
	serializedObject.ApplyModifiedProperties();
}

The call to DrawMultiLineString uses code directly from NGUI’s UILabelInspector, and is not available unless you have NGUI for Unity.