Return Value 戻り値
A widget that triggers url
when events are generated for a URLSession
with the specified identifier.
Availability 有効性
Technology
A widget that triggers url
when events are generated for a URLSession
with the specified identifier.
matchingBlock
A closure that takes a URLSession
identifier and returns a Boolean value indicating whether to perform the action.
urlSessionEvent
A closure that takes a string parameter called identifier
and a closure called completion
.
When a widget initiates a background network request, the system delivers events related to the request directly to the widget extension instead of the containing app. To process the events, do the following:
Use the identifier
parameter to determine if a corresponding URLSession
object exists. If the system has not terminated your widget extension, maintain a reference to the same URLSession
object you used for the original background network request. If the system has terminated your widget extension, use the identifier to create a new URLSession
object so it can receive the events. You might consider lazily initializing, and caching, the URLSession
objects in a central location so that your code works regardless of whether your extension remains active, is suspended, or is terminated.
Store a reference to the completion
handler to invoke after all events have been delivered.
After the system calls the URLSession
delegate’s url
method, invoke the completion
handler.