I'm trying to segue from a mapView
to a page that contains a snapshot of a chosen location on that mapView.
Here is my prepareForSegue
method:
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"LocationConfirmSegue"]) {
LocationConfirmationViewController *vc = segue.destinationViewController;
MKCoordinateSpan span;
span.longitudeDelta = mapFocusSpan;
span.latitudeDelta = mapFocusSpan;
MKCoordinateRegion region;
region.center = *currentPinLocation;
region.span = span;
MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc] init];
options.region = region;
options.size = CGSizeMake(270, 180);
MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:options];
[snapshotter startWithCompletionHandler: ^(MKMapSnapshot * _Nullable snapshot, NSError * _Nullable error) {
if (error) {
NSLog(@"%@", error);
return;
}
vc.mapSnapshot = snapshot.image;
}];
}
}
I can pass information to the destination VC fine outside of the snapshotter's completion handler. The code all works fine, too––snapshot.image does indeed return a UIImage*––however it's not being passed to the destination view controller. When I try to access the mapSnapshot property in that view controller, I get (null).
Take advantage of Apple's OpenGLES screenshot to prevent the inability to get a layer image of the map or a black screen