Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Create GLKView before binding it and resuming
Browse files Browse the repository at this point in the history
Or: don’t resume the map until the application has entered the foreground.

UIApplicationWillEnterForegroundNotification is posted before UIApplicationDidBecomeActiveNotification, while the application is still in the background. That caused -createGLView to bail but did not cause the rest of -wakeGL: to bail. We would create the GLKView only after attempting to bind it (a no-op), resulting in a black view.

Fixes #1855.
  • Loading branch information
1ec5 committed Jul 11, 2015
1 parent 00308be commit f96fef8
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions platform/ios/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ - (void)commonInit
[self createGLView];
}


self.accessibilityLabel = @"Map";
self.backgroundColor = [UIColor clearColor];
self.clipsToBounds = YES;
Expand Down Expand Up @@ -251,7 +250,7 @@ - (void)commonInit
//
_annotationIDsByAnnotation = [NSMapTable mapTableWithKeyOptions:NSMapTableStrongMemory valueOptions:NSMapTableStrongMemory];

_annotationImages = [NSMutableDictionary new];
_annotationImages = [NSMutableDictionary dictionary];

std::string defaultSymbolName([MGLDefaultStyleMarkerSymbolName UTF8String]);
_mbglMap->setDefaultPointAnnotationSymbol(defaultSymbolName);
Expand Down Expand Up @@ -376,9 +375,7 @@ - (void)commonInit

- (void)createGLView
{
if (_context || [UIApplication sharedApplication].applicationState == UIApplicationStateBackground) {
return;
}
if (_context) return;

// create context
//
Expand Down Expand Up @@ -415,17 +412,6 @@ - (void)createGLView
});
}

- (void)viewWillEnterForeground
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIApplicationWillEnterForegroundNotification
object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIApplicationDidBecomeActiveNotification
object:nil];
[self commonInit];
}

- (void)reachabilityChanged:(NSNotification *)notification
{
MGLReachability *reachability = [notification object];
Expand Down Expand Up @@ -797,11 +783,11 @@ - (void)wakeGL:(__unused NSNotification *)notification
{
MGLAssertIsMainThread();

[self createGLView];
if (self.isDormant)
if (self.isDormant && [UIApplication sharedApplication].applicationState != UIApplicationStateBackground)
{
self.dormant = NO;

[self createGLView];
[MGLMapboxEvents validate];

self.glSnapshotView.hidden = YES;
Expand Down

0 comments on commit f96fef8

Please sign in to comment.