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

[ios] black screen with offline maps #4643

Closed
rsimenok opened this issue Apr 7, 2016 · 8 comments
Closed

[ios] black screen with offline maps #4643

rsimenok opened this issue Apr 7, 2016 · 8 comments

Comments

@rsimenok
Copy link

rsimenok commented Apr 7, 2016

iOS
MapBox 3.2.0

Hello, i have problems with downloading offline package.

Firstly I hope i check right if offline pack available, because if i had offline pack i don't need to download it again.

if ([[MGLOfflineStorage sharedOfflineStorage] packs].count == 0) {
    NSLog(@"START OFFLINE PACK DOWNLOAD");
    [[YMapDownloader downloader] startOfflinePackDownload];
}

YMapDownloader is my NSObject, where i put code from official example, here is full code of my class

how i create region

CLLocationCoordinate2D sw = CLLocationCoordinate2DMake(32.147344404778963, -64.89344945400417);
CLLocationCoordinate2D ne = CLLocationCoordinate2DMake(32.471673244603323, -64.643860247099894);

id <MGLOfflineRegion> region = [[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:nil
                                                                              bounds:MGLCoordinateBoundsMake(sw, ne)
                                                                       fromZoomLevel:9.8
                                                                         toZoomLevel:20.0];

so when i call startOfflinePackDownload i start downloading

// Start downloading.
[pack resume];

But i don't get any notification about progress, even no NetworkActivityIndicator in status bar.
After i don't see any activity i try to open map and it was black, i mean black screen, no map. When i commented pack downloading, recompile app and open map i start get warnings:

Unable to make space for entry
2016-04-08 02:11:54.316 MyApp[420:64640] [WARNING]

so as i understand it's connected #4411

Steps to trigger behavior

Use code from example but with this region:

CLLocationCoordinate2D sw = CLLocationCoordinate2DMake(32.147344404778963, -64.89344945400417);
CLLocationCoordinate2D ne = CLLocationCoordinate2DMake(32.471673244603323, -64.643860247099894);

id <MGLOfflineRegion> region = [[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:nil
                                                                              bounds:MGLCoordinateBoundsMake(sw, ne)
                                                                       fromZoomLevel:9.8
                                                                         toZoomLevel:20.0];

Expected behavior

Downloaded offline pack.

Actual behavior

No pack downloaded.

@1ec5
Copy link
Contributor

1ec5 commented Apr 7, 2016

Where are you checking the number of packs? That array is populated asynchronously and may be nil for an undefined period of time after launch. You should register for KVO change notifications on that key path and only start the download when the change kind is NSChangeKindSetting.

The SDK doesn't handle displaying the network activity indicator – your application can manage that.

/cc @friedbunny

@rsimenok
Copy link
Author

rsimenok commented Apr 8, 2016

Where are you checking the number of packs?

@1ec5 in viewWillAppear of my initial ViewController. He doesn't contains MapBox map.

@1ec5
Copy link
Contributor

1ec5 commented Apr 8, 2016

I wonder if that's too soon. Can you check whether packs is in fact nil rather than empty? (The code you posted above doesn't distinguish.) If it's nil, you should try KVO to detect when the packs are discovered. See MBXOfflinePacksTableViewController for inspiration.

@rsimenok
Copy link
Author

rsimenok commented Apr 8, 2016

@1ec5 not nil...(

screen shot 2016-04-08 at 11 27 34
I wonder why after [pack resume]; i doesn't get any notifications.

Well i think i found problem.

[[YMapDownloader downloader] startOfflinePackDownload];
+(YMapDownloader *)downloader {
    return [[YMapDownloader alloc] init];
}

YMapDownloader instance dying very fast, so i didn't get notifications, but as i understand pack was loading.
NOTE: Black screen means that map is loading.
So i take strong ref on YMapDownloader instance and all is working, but i get warnings:
[WARNING] {DefaultFileSource}[Database]: Unable to make space for entry

And the last question, is it possible to check for packs on application start?

@rsimenok rsimenok closed this as completed Apr 8, 2016
@1ec5
Copy link
Contributor

1ec5 commented Apr 8, 2016

It isn't possible to check synchronously at application launch, unfortunately.

@rsimenok
Copy link
Author

@1ec5 Two more question please :)

  1. How to get all size of region(all packs)?
  2. How to detect if user downloaded all packs for region or no? Or detect if region was downloaded?

@lethianqt94
Copy link

I have same questions:

  1. How to get all size of region(all packs)?
  2. How to detect if user downloaded all packs for region or no? Or detect if region was downloaded?

@1ec5
Copy link
Contributor

1ec5 commented Jun 13, 2016

  1. For each offline pack in MGLOfflineStorage.packs, call -requestProgress. The progress arrives asynchronously, so register for MGLOfflinePackProgressChangedNotification notifications, which come with progress information including the size taken up by the region. You'll need to sum up the sizes yourself.
  2. Call -requestProgress on the pack, as above.

See the offline storage documentation for more information about notifications and progress.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants