-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMKMapSnapshotter+Promise.swift
More file actions
50 lines (42 loc) · 1.42 KB
/
MKMapSnapshotter+Promise.swift
File metadata and controls
50 lines (42 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import MapKit
#if !PMKCocoaPods
import PromiseKit
#endif
/**
To import the `MKMapSnapshotter` category:
use_frameworks!
pod "PromiseKit/MapKit"
And then in your sources:
import PromiseKit
*/
extension MKMapSnapshotter {
#if swift(>=4.2)
/// Starts generating the snapshot using the options set in this object.
/// - Note: cancelling this promise will cancel the underlying task
/// - SeeAlso: [Cancellation](http://promisekit.org/docs/)
public func start() -> Promise<Snapshot> {
return Promise<Snapshot>(cancellableTask: MKMapSnapshotterTask(self)) { start(completionHandler: $0.resolve) }
}
#else
/// Starts generating the snapshot using the options set in this object.
/// - Note: cancelling this promise will cancel the underlying task
/// - SeeAlso: [Cancellation](http://promisekit.org/docs/)
public func start() -> Promise<MKMapSnapshot> {
return Promise<MKMapSnapshot>(cancellableTask: MKMapSnapshotterTask(self)) { start(completionHandler: $0.resolve) }
}
#endif
}
private class MKMapSnapshotterTask: CancellableTask {
let snapshotter: MKMapSnapshotter
var cancelAttempted = false
init(_ snapshotter: MKMapSnapshotter) {
self.snapshotter = snapshotter
}
func cancel() {
snapshotter.cancel()
cancelAttempted = true
}
var isCancelled: Bool {
return cancelAttempted && !snapshotter.isLoading
}
}