BT

Your opinion matters! Please fill in the InfoQ Survey!

What's New in iOS 9: Enhancements to Existing Frameworks

| Posted by Sergio De Simone Follow 5 Followers on Sep 22, 2015. Estimated reading time: 17 minutes |

A note to our readers: As per your request we have developed a set of features that allow you to reduce the noise, while not losing sight of anything that is important. Get email and web notifications by choosing the topics you are interested in.

At WWDC 2015, Apple introduced iOS 9. Although the new SDK does not introduce as many new or enhanced features as iOS 8, which included more than 4,000 new APIs, it does still provide a wealth of new functionality and enhancements. Along with the new SDK, iOS 9 is also marked by new developer tools to support some of its features, and new releases of Apple’s major programming languages, Swift and Objective-C.
This series aims at introducing all that is essential for developers to know about building apps for the latest release of Apple’s mobile OS. It comprises five articles that will cover what’s new in iOS 9 SDK, new features in Swift, Objective-C, and developer tools, and Apple’s new bitcode.
This InfoQ article is part of the series “IOS 9 For Developers ”. You can subscribe to receive notifications via RSS.

 

After reviewing new frameworks introduced with iOS 9 in the first instalment of this series, in this second article about iOS 9, we focus on enhancements to existing frameworks.

UIKit Framework

The UIKit framework includes many enhancements. Among the most significant ones:

  • the UIStackView class allows you to manage subviews that can be arranged vertically or horizontally without directly using Auto Layout. It allows to customize its appearance through a number of properties such as:
    • axis to determine the stack’s orientation
    • distribution and alignment to determine the layout of subviews along and perpendicular to the stack’s axis
    • spacing to set the minimun spacing between the subviews.
  • a new UIApplicationDelegate method allows to support the new open-in-place functionality, which allows to open a document without making a copy of it.
  • new NSLayoutAnchor, and NSLayoutDimension classes that can be used together with UIView’s new layout anchors, such as leadingAnchor and widthAnchor), to define layout constraints through higher level abstrations. This is an example of how you can constraint a subview layout with respect of its superview:
let margins = view.layoutMarginsGuide
 
subview.leadingAnchor.constraintEqualToAnchor(margins.leadingAnchor).active
= true
subview.trailingAnchor.constraintEqualToAnchor(margins.trailingAnchor).active = true
  • new LayoutGuide class aims to make away with “dummy views” that were used with several Auto Layout techniques, e.g. using a “dummy” container view for a set of objects that you want to center all together, or using a “dummy” spacer view so you can use constraints on it. Layout guides do not define new views, but simply create rectangular regions that can interact with Auto Layout. This is a short example of how you could go about creating two equal spacers between three buttons with Layout Guides:
let space1 = UILayoutGuide()
view.addLayoutGuide(space1)

let space2 = UILayoutGuide()
view.addLayoutGuide(space2)
 
space1.widthAnchor.constraintEqualToAnchor(space2.widthAnchor).active = true
saveButton.trailingAnchor.constraintEqualToAnchor(space1.leadingAnchor).active = true
cancelButton.leadingAnchor.constraintEqualToAnchor(space1.trailingAnchor).active = true
cancelButton.trailingAnchor.constraintEqualToAnchor(space2.leadingAnchor).active = true
clearButton.leadingAnchor.constraintEqualToAnchor(space2.trailingAnchor).active = true

WKWebView and Safari View Controller

WKWebView was introduced with iOS 8 and now includes a few enhancements that make it possible to:

  • securely load an HTML file (loadFileURL)
  • load binary data (loadData) by specifying an NSData container and its MIME-type.
  • override the user agent string (customUserAgent)

WKWebsiteDataStore is a new class that allows to manage data that is stored by websites such as cookies, caches, and other stuff. It is available as a property on the web view WKWebViewConfiguration configuration property and allows to remove data based on its type, or its modification date, or even replace the store with a non-persistent store, thus providing a cheap private browsing mode.

SFSafariViewController is a new class that implements a full in-app browsing experience similar to that provided by Safari. It supports:

  • a familiar UI for Safari users
  • user data sharing with Safari for cookies, autofill, etc.
  • Safari Reader
  • Content Blocking

A SFSafariViewController can be instantiated by providing the URL of the page to browse to and a delagete property that allows to control its behaviour:

class SFSafariViewController : UIViewController {
    weak var delegate: SFSafariViewControllerDelegate?
    init(URL: NSURL)
}

The delegate protocol supports two methods: one for handling any custom activities that the user may initiate from the share sheet, the other to respond to the user tapping on the “Done” button.

protocol SFSafariViewControllerDelegate : NSObjectProtocol {
    optional func safariViewController(controller: SFSafariViewController,
activityItemsForURL URL: NSURL, title: String?) -> [UIActivity]
    optional func safariViewControllerDidFinish(controller:
SFSafariViewController)
}

Overall, SFSafariViewController promises to allow developers to save a lot of time implementing their in-app browser and to provide a superior user experience. A notable use-case where SFSafariViewController will provide a huge benefit in comparison to UIWebKit/WKWebView is when doing authentication with a third-party web service. Since SFSafariViewController shares Safari’s cookies, in many cases, your app will be able to authenticate the user without the user doing anything; and in other cases, it will use auto-fill to make it easier on the user.

Core Data

iOS 9 brings a few API enhancements to Core Data:

  • NSManagedObject now allows to check if an object has been modified through the hasPersistentChangedValues method.
  • NSManagedObject provides the objectIDsForRelationshipNamed method to fetch all IDs of objects belonging to a relationship. This can be useful to speed up retrieving all objects in that relationship:
let relations = person.objectIDsForRelationshipNamed("family") let fetchFamily = NSFetchRequest(entityName: “Person") fetchFamily.fetchBatchSize = 100 fetchFamily.predicate = NSPredicate(format: "self IN %@", relations) let batchedRelations = managedObjectContext.executeFetchRequest(fetchFamily) 
  • NSManagedObjectContext adds a new refreshAllObjects method that will refresh all registered objects in a context while also preserving unsaved changes.
  • NSPersistentStoreCoordinator now provides methods to destroy or replace a persistent store, which is safer than using NSFileManager to delete the associated file.
  • Objects can be deleted without first loading them into memory thanks to NSBatchDeleteRequest, which acts directly on the persistent store. Unfortunately, deletions are not reflected in existing contexts, which could contain stale objects and might require a reset.
  • A new strategy should make lightweight migrations more reliable thanks to the NSManagedObjectModel being saved in Core Data persistent store and read from there in case of migration.
  • A new schema for automatic synthesizing of NSManagedObject subclasses based on categories and extensions should make it easier to handle changes in the model in the face of customization of concrete classes.

HealthKit

A bunch of new data types have been introduced, including water intake, UV exposure, and 6 reproductive health types. Furthermore, source revisions and devices will provide more details about where the data comes from, such as the motion processor, an iPhone, an external Bluetooth device, and which app and version created it.

Deleting objects has become more flexible thanks to the possibility of deleting multiple objects and querying deleted objects through the HKAnchoredObjectQuery class.

HomeKit

HomeKit in iOS 9 will make it easier to manage changes in your home environment, such as moving a light around. A new targeted delegate mechanism will tell the app exactly which room and which accessory was affected by the change, whereas previously a whole new home manager was provided and the app had to figure out what changed by comparing their contents. This is related to another change in most of HomeKit classes, which will now provide a unique identifier to make it easier to associate context data to HomeKit objects.

The iOS 8 user management API has been deprecated and replaced through a new manageUsersWithCompletionHandler method that will display a full view controller to manage users in their homes.

iOS 9 introduces four predefined scenes, i.e. a predefined collection of settings for a given situation. The four scenes are: getting up, leaving home, returning home, and going to bed. Scenes can be customized and actions can be attached to them.

Accessory categories are another new feature, aiming to make it possible to provide a richer user experience by, e.g., showing an icon representing that accessory category.

A sample code project is provided on Apple dev site.

MapKit

MapKit on iOS 9 provides new APIs:

  • pinTintColor, to customize pin colors.
  • detailCalloutAccessoryView, to be able to fully define a callout view through a custom view.
  • showsTraffic, to show or hide traffic information.
  • showsScale, to show or hide map scale information.
  • showsCompass, to show or hide a compass.
  • new Transit transport type (`MKDirectionsTransportType), to be used with MKDirectionsRequest to get expected arrival timing and expected departure timing for transit. This is similar to the already existing Automobile and Walking options.
  • openInMapsWithLaunchOptions, to launch the Maps app in transit mode for better integration with other apps.
  • SatelliteFlyover and HybridFlyover map type (MKMapType), to display a flyover map, which provides a 3D photo-realistic model of various cities and landmarks.

UIKit Dynamics

UIKit Dynamics, introduced with iOS 8 to make it easier to animate interfaces with physics-based realistic effects, brings a host of new features:

  • non-rectangular collision bounds, including elliptical and custom path (Bezier) bounds. These can be specified through the new collisionBoundsType and collisionBoundingPath optional properties in the UIDynamicItem protocol.
  • UIDynamicItemGroup allows multiple items to behave like one in the engine. This will allows to add a behavior to the group that will affect all of its items. Groups cannot be nested and are useful to represent concave or other complex shapes.
  • UIFieldBehavior is a new behavior that models vector force fields. A UIFieldBehavior can be attached to a region of the reference view and will affect how items behave in that region, similarly to the old UIGravityBehavior. Several built-in field types are provided, including radial gravity, spring field, electric and magnetic fields and others, each one characterized by its own specific parameters. It is also possible to implement a custom field by providing a block that will take the position, velocity, mass, charge, and time and will determine any resulting forces.
  • UIDynamicItemBehavior has been extended to support new charge and anchored properties that are required by force fields.
  • UIAttachmentBehavior supports new attachment types to constraint the relative distance between two items:
  • limit attachment, which behaves like a rope connecting two items
  • fixed attachment, which allows no relative movement
  • pin attachment, which allows two items to keep their distance while rotating aroung a fixed point
  • sliding attachment, which will allow some relative sliding along a given axis but no relative rotation.
  • UISnapBehavior has been extended to customize both the damping effect and the snap point to better control the snap-like effect when moving an item from a location to another.
  • LLDB supports a new debugEnabled property of animator objects that will visualize an overlay showing fields, collision bounds, and attachments.

A sample project is available on Apple dev site.

Visual Effects

UIKitVisualEffectView have been enhanced to support:

  • easy animation of a UIKitVisualEffectView’s bounds
  • blur animation
  • _whatsWrongWithThisEffect diagnostic pseudo-method that can be called in LLDB to know what is not correct with a given effect.

A sample project is available on Apple developer site.

Core Audio

AVAudioEngine, which was introduced in iOS 8 (and OS X 10.10) to simplify handling of low latency, real-time audio, presents three main new features:

  • Splitting support, which allows to split the output of a node into multiple paths that can be processed together, e.g. by applying different effects to them, and then mixed back. This feature is enabled by a new class called AVAudioConnectionPoint.

  • Audio format conversion support, which is made possible by two new classes, AVAudioCompressedBuffer and AVAudioConverter, which provide a high-level equivalent of audio conversion from the C Audio Toolbox Framework.

  • AVAudioSequencer, which supports playback of MIDI files.

Furthermore, a new feature of iOS 9 is Inter-device Audio Mode, which allows use an iPad or iPhone to record digitally to a Mac running OS X 10.11 through the USB to lightning cable that is provided with the device.

CoreImage

CoreImage on iOS 9 provides better integration with Metal and more filters:

  • Metal integration: Metal textures are now first-class citizens in CoreImage. They can be used as an input to CoreImage, which is also able to provide a Metal texture on its output. Metal can also be used to render filters and some built-in filters are built of top of Metal shaders.
  • Same filters across platforms: CoreImage implementation is unified across OS X and iOS 9. This means that about 200 filters are now available on iOS, including new ones such as Comic Effect, CMYL Halftone, Page Curl, Noise Reduction and so on.
  • New detectors to do things like detecting faces in an image (CIFaceDetector), detecting QR codes in an image (CIBarcodeDetector), or detecting rectangles in an image (CIRectangleDetector).
  • Color management: this feature has always been present on Core Image for OS X and has been ported to iOS 9.

Core Motion

CoreMotion add supports for pace, cadence, pressure sensing, and relative altitude:

  • Pace is a new feature privided by CMPedometer that gives the user’s currentPace in units of time over distance. This is the instantaneous pace, and not some averaged value based on historical data.
  • cadence is similar to pace, in that it represents the rate of steps, which is extremely important for runners.
  • Pressure sensing is provided by the altimeter sensor through the CMAltimeter API. It provides the raw pressure as it is measured by the sensor and relative altitude. Altitude is relative to the first sample provided, which will have a relative altitude of zero. It can be used to detect floor changes, while it is not reliable for things like the user raising their arm. Changes in weather conditions may affect altimeter pression evaluation, so it is not advised to use it over long time spans.

A sample project is available on Apple developer site.

Metal

Metal has introduced many new features, both on iOS and OS X:

  • Metal feature sets, which represent a collection of capabilities provided by a given GPU generation. Each feature set is identified by a name unique to a hardware generation, e.g. iOS_GPUFamily2_v1. You can check whether a given Metal device supports a given feature set by means of the supportsFeatureSet: method. There are currently 4 feature sets for the iOS platform and 1 for OS X.
  • Shader constant updates have been made more efficient by splitting the existing setVertexBuffer:offset:atIndex: method into two: setVertexBuffer:atIndex: and setVertexBufferOffset:atIndex:. Thanks to this, if you have a series of draw operations to execute, you can set the buffer just once, then for each draw operation, you update the offset into the buffer.
  • New memory model aimed at supporting both unified and discrete memory models with minimal code changes. In particular, two new storage modes are available to specify where resources should reside: private storage mode and managed storage mode, which complement the already existing shared storage mode:
    • In shared mode resources are stored in a shared memory accessible to both the CPU and the GPU which is kept coherent.
    • In private mode, the GPU uses its own memory which is not accessible to the CPU, and can thus store information in a way that is optimal, by using frame buffer compression, e.g. Private memory is particularly suited to system with discrete memory, which is memory the GPU can access really fast. The drawback is that resource must be specifically moved to private memory.
    • In managed mode, which is available only on OS X, two copies of resources are kept, one in shared memory and the other in discrete memory. This mode attempts to strike a balance between ease of use and performance.
  • New texture usage hints allow to declare how a texture will be used, so Metal can optimize for that usage. Available descriptors are:
  • MTLTextureUsageUnknown
  • MTLTextureUsageShaderRead
  • MTLTextureUsageShaderWrite
  • MTLTextureUsageRenderTarget
  • MTLTextureUsageBlit.
  • New ASTC compression format, which is a high-quality format more efficient than PVRTC and EAC.

SpriteKit

SpriteKit in iOS 9 provides both new features and better integration with the rest of the system:

  • a new SKCameraNode class provides a way to easily determine which portion of a scene is visible by moving its center. Being a node, an SKCameraNode can be used with actions, supports constraints, apply rotation and scaling, etc.
  • SKAudioNode provides support for adding positional, environmental source sources. This allows to define a listener node so a given SKAudioNode will be played louder when its distance from the listener gets smaller, or more one-sided and distant when it moves to the side of the scene.
  • SKReferenceNode and named SKAction make it possible to serialize a node or an action and reuse it more easily when required. The entity will be loaded from disk only on the first instantiation of the corresponding node.
  • Actions can be controlled in more ways thanks to new methods such as play, pause, and animateWithNormalTextures:, which provides support for updating lighting while an action is running.

Furthermore, new tools have been introduced:

  • Texture atlas
  • Particle editor
  • Xcode Quicklook, which allows to get a preview of a texture inside of the Playground or Xcode debugger.
  • The 2D editor has been enhanced with new features to support the camera, audio nodes, and reference nodes.
  • A new Action editor, which allows to define actions through a timeline and providing support for both 2D and 3D actions.

A sample project is available on Apple developer site.

Multitasking enhancement

iOS 9 introduces a few enhancements that allow users to execute multiple apps at the same time. Those enhancements are only available on recent iPads, including the iPad Mini 2 and 3, and the iPad Air 1 and 2. They can be resumed as follows:

  • Slide over: a mode where a second app is shown in a overlay view on the right side of the screen.
  • Split View: a mode that allows for two apps to be run side-by-side. This mode is only available on the iPad Air 2.
  • Picture in picture: a mode that allows a video to be played in a moveable, resizeable floating window.

The possibility for two apps to be run at the same time has several important implications for the developer:

  • an app cannot assume to have exclusive access to CPU, GPU, memory, and I/O;

  • an app running in the foreground could be running aside of another app, or a Picture in picture window could be playing;

  • it is not longer appropriate to use the screen’s bounds to determine the app’s visible area; the app’s window’s bounds should be used instead;

  • Auto Layout will not guarantee that an app will play well with slide over and split view, but, according to Apple, “it makes doing so easier” thanks to Auto Layout size classes;

  • the required LaunchScreen.storyboard file must employ Auto Layout;

  • the methods in the UITraitEnvironment and UIContentContainer protocols allow to respond to trait collection and size changes;

  • due to iOS tight resource management, it is even more important to use instruments and make sure there are no leaks, or the app’s memory is not growing indefinitely;

  • an app should respond properly to state transition delegate method calls to ensure all unnecessary resources are freed and doing what required to ensure that the app’s UI can be snapshotted on a state change to provide a smooth user experience;

  • a good practice is testing an app when running side-by-side with a resource-intensive app such as Maps set to Satellite view and performing a flyover animation.

Apple strongly suggests that all apps support slide over and split view, with the exception of camera-centric apps and full-device apps, suche as games or apps that user the iPad sensors as part of their gameplay. Nevertheless, an app can opt out of slide over and split view by setting the UIRequiresFullScreen Info.plist property to YES.

A sample project is available on Apple developer site.

Next Article in Series

The next article in the series will provide an in-depth review of the new ad blocking mechanism in Safari for iOS 9.

About the Author

Sergio de Simone  is a software engineer. Sergio has been working as a software engineer for over fifteen years across a range of different projects and companies, including such different work environments as Siemens, HP, and small startups. For the last few years, his focus has been on development for mobile platforms and related technologies. He is currently working for BigML, Inc., where he leads iOS and OS X development.

 

At WWDC 2015, Apple introduced iOS 9. Although the new SDK does not introduce as many new or enhanced features as iOS 8, which included more than 4,000 new APIs, it does still provide a wealth of new functionality and enhancements. Along with the new SDK, iOS 9 is also marked by new developer tools to support some of its features, and new releases of Apple’s major programming languages, Swift and Objective-C.
This series aims at introducing all that is essential for developers to know about building apps for the latest release of Apple’s mobile OS. It comprises five articles that will cover what’s new in iOS 9 SDK, new features in Swift, Objective-C, and developer tools, and Apple’s new bitcode.
This InfoQ article is part of the series “IOS 9 For Developers ”. You can subscribe to receive notifications via RSS.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT