Instance Method

updateApplicationContext(_:)

Sends a dictionary of values that a paired and active device can use to synchronize its state.

Declaration

func updateApplicationContext(_ applicationContext: [String : Any]) throws

Parameters

applicationContext

A dictionary of property list values. You define the meaning of the dictionary contents. This parameter must not be nil.

error

On input, a pointer to an error object. On output, the pointer is set to an error object if a problem occurred. You may specify nil if you do not care about error information.

Return Value

An error indicating the reason why the update could not be sent to the counterpart. Calls to this method can fail when the dictionary does not contain property-list data types.

Discussion

Use this method to transfer a dictionary of data items to the counterpart app. The system sends context data when the opportunity arises, with the goal of having the data ready to use by the time the counterpart wakes up. The counterpart’s session delivers the data to the session(_:didReceiveApplicationContext:) method of its delegate. A counterpart can also retrieve the data from the receivedApplicationContext property of its session.

This method replaces the previous dictionary that was set, so you should use this method to communicate state changes or to deliver data that is updated frequently anyway. For example, this method is well suited for updating your app’s glance.

You may call this method when the counterpart is not currently reachable.

This method can only be called while the session is active—that is, the activationState property is set to activated. Calling this method for an inactive or deactivated session is a programmer error.

See Also

Managing Background Updates

var applicationContext: [String : Any]

The most recent contextual data sent to the paired and active device.

var receivedApplicationContext: [String : Any]

A dictionary containing the last update data received from a paired and active device.