MGLOfflinePack
@interface MGLOfflinePack : NSObject
An MGLOfflinePack
represents a collection of resources necessary for viewing
a region offline to a local database.
To create an instance of MGLOfflinePack
, use the
+[MGLOfflineStorage addPackForRegion:withContext:completionHandler:]
method.
A pack created using -[MGLOfflinePack init]
is immediately invalid.
Example
MGLOfflineStorage.shared.addPack(for: region, withContext: context) { (pack, error) in
guard let pack = pack else {
// If adding the pack fails, log an error to console.
print("Error:", error?.localizedDescription ?? "unknown error adding pack at \(#file)(\(#line)) in \(#function)")
return
}
// Start an MGLOfflinePack download
pack.resume()
}
-
The region for which the pack manages resources.
Declaration
Objective-C
@property (nonatomic, readonly) id<MGLOfflineRegion> _Nonnull region;
Swift
var region: MGLOfflineRegion { get }
-
Arbitrary data stored alongside the downloaded resources.
The context typically holds application-specific information for identifying the pack, such as a user-selected name.
Declaration
Objective-C
@property (nonatomic, readonly) NSData *_Nonnull context;
Swift
var context: Data { get }
-
The pack’s current state.
The state of an inactive or completed pack is computed lazily and is set to
MGLOfflinePackStateUnknown
by default. To request the pack’s status, use the-requestProgress
method. To get notified when the state becomes known and when it changes, observe KVO change notifications on this pack’sstate
key path. Alternatively, you can add an observer forMGLOfflinePackProgressChangedNotification
s about this pack that come from the default notification center.Declaration
Objective-C
@property (nonatomic, readonly) MGLOfflinePackState state;
Swift
var state: MGLOfflinePackState { get }
-
The pack’s current progress.
The progress of an inactive or completed pack is computed lazily, and all its fields are set to 0 by default. To request the pack’s progress, use the
-requestProgress
method. To get notified when the progress becomes known and when it changes, observe KVO change notifications on this pack’sstate
key path. Alternatively, you can add an observer forMGLOfflinePackProgressChangedNotification
s about this pack that come from the default notification center.Declaration
Objective-C
@property (nonatomic, readonly) MGLOfflinePackProgress progress;
Swift
var progress: MGLOfflinePackProgress { get }
-
Resumes downloading if the pack is inactive.
When a pack resumes after being suspended, it may begin by iterating over the already downloaded resources. As a result, the
progress
structure’scountOfResourcesCompleted
field may revert to 0 before rapidly returning to the level of progress at the time the pack was suspended.To temporarily suspend downloading, call the
-suspend
method.Declaration
Objective-C
- (void)resume;
Swift
func resume()
-
Temporarily stops downloading if the pack is active.
A pack suspends asynchronously, so some network requests may be sent after this method is called. Regardless, the
progress
property will not be updated until-resume
is called.If the pack previously reached a higher level of progress before being suspended, it may wait to suspend until it returns to that level.
To resume downloading, call the
-resume
method.Declaration
Objective-C
- (void)suspend;
Swift
func suspend()
-
Request an asynchronous update to the pack’s
state
andprogress
properties.The state and progress of an inactive or completed pack are computed lazily. If you need the state or progress of a pack whose
state
property is currently set toMGLOfflinePackStateUnknown
, observe KVO change notifications on this pack’sstate
key path, then call this method. Alternatively, you can add an observer forMGLOfflinePackProgressChangedNotification
about this pack that come from the default notification center.Declaration
Objective-C
- (void)requestProgress;
Swift
func requestProgress()