MKMapSnapshotter Class Reference

Inherits from
Conforms to
Availability
Available in iOS 7.0 and later.
Declared in
MKMapSnapshotter.h

Overview

An MKMapSnapshotter object captures map-based imagery asynchronously. Use instances of this class in situations where you want to capture the iOS-provided map content, including the map tiles and imagery. The snapshotter object always captures the best image possible, loading all of the available map tiles before capturing the image.

You use a snapshotter object in conjunction with an MKMapSnapshotOptions object. The snapshot options specify the map configuration to use during the capture process, including which portion of the map you want to capture.

Tasks

Initializing a Snapshotter Object

Generating a Snapshot

Properties

loading

A Boolean indicating whether the snapshotter is currently generating an image. (read-only)

@property (nonatomic, readonly, getter=isLoading) BOOL loading;
Availability
  • Available in iOS 7.0 and later.
Declared In
MKMapSnapshotter.h

Instance Methods

cancel

Cancels the current request to create a snapshot.

- (void)cancel
Discussion

If the snapshotter is not in the process of generating the snapshot, calling this method does nothing.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKMapSnapshotter.h

initWithOptions:

Initializes and returns a snapshotter object based on the specified options.

- (instancetype)initWithOptions:(MKMapSnapshotOptions *)options
Parameters
options

The options to use when capturing the map imagery. If you specify nil for this property, the snapshotter uses a set of default options that capture an image of the current user’s country.

Return Value

An initialized snapshotter option.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKMapSnapshotter.h

startWithCompletionHandler:

Submits the request to create a snapshot and delivers the results to the specified block.

- (void)startWithCompletionHandler:(MKMapSnapshotCompletionHandler)completionHandler
Parameters
completionHandler

The block to call with the resulting snapshot. This block is executed on the app’s main thread and must not be nil.

Discussion

Call this method to begin generating a snapshot image based on the specified parameters. This method executes the request asynchronously.

The snapshotter delivers the final image to your app only when it is running in the foreground. The snapshotter must render the final image while your app is in the foreground. If you start generating a snapshot while the app is in the background, or if your app moves to the background while a snapshot is in progress, this behavior delays the delivery of the snapshot until your app returns to the foreground.

In OS X, this method creates both standard and high-resolution representations of the map data and includes both in the returned image object. In iOS, you must specify the image scale you want using the snapshot options, which default to the scale on the current device.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKMapSnapshotter.h

startWithQueue:completionHandler:

Submits the request to create a snapshot and executes the resulting block on the specified queue.

- (void)startWithQueue:(dispatch_queue_t)queue completionHandler:(MKMapSnapshotCompletionHandler)completionHandler
Parameters
queue

The dispatch queue on which to execute the block specified by the completionHandler parameter.

completionHandler

The block to call with the resulting snapshot. This block must not be nil.

Discussion

Call this method to begin generating a snapshot image based on the specified parameters. This method executes the request asynchronously. When rendering is complete, the snapshotter delivers the results to your block on the dispatch queue in the queue parameter.

The snapshotter delivers the final image to your app only when it is running in the foreground. The snapshotter must render the final image while your app is in the foreground. If you start generating a snapshot while the app is in the background, or if your app moves to the background while a snapshot is in progress, this behavior delays the delivery of the snapshot until your app returns to the foreground.

In OS X, this method creates both standard and high-resolution representations of the map data and includes both in the returned image object. In iOS, you must specify the image scale you want using the snapshot options, which default to the scale on the current device.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKMapSnapshotter.h

Constants

MKMapSnapshotCompletionHandler

A block that processes the results of a snapshot request.

typedef void (^MKMapSnapshotCompletionHandler)(MKMapSnapshot *snapshot, NSError *error);
Discussion

This block takes the following parameters:

snapshot

The image data that was generated or nil if an error occurred

error

The error that occurred or nil if the snapshot was generated successfully.

Availability
  • Available in iOS 7.0 and later.
Declared In
MKMapSnapshotter.h