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

Discuss new API and offline maps work #79

Closed

Description

This issue is for discussing what needs to be done to polish the pile of commits from #73 into shape for merging into master. The changes implement a substantially revised API for MBXMapKit, including performance caching and offline maps. The offline maps part just recently hit the point of functionality, and now it needs some polish.

A couple notes:

  1. I created the mapbox/issue79 branch which squashes all the commits from the issue73 branch.
  2. See Discuss API refinements, including caching #73 (comment) for some initial thoughts from @incanus on what needs to happen next.

Todo:

  • Track down and fix any glitches with the sample app (in particular, check state transitions for offline maps)
  • Move the v030 iOS sample app to replace the old sample app
  • Figure out what to do about OS X support and the OS X sample app (see cut OS X support #78)
  • Revise the readme including a conceptual overview of how the new API works and how it's meant to be used. See How Does Carmen Work?
  • Write something up about how to use the sample app to demo and test the API. Perhaps this belongs in the readme, or perhaps it should go elsewhere
  • De-cruft the code and the API: check for orphaned code, unnecessary stuff in header files, anything that's likely to cause confusion about proper usage, etc.
  • Implement an option to enable iCloud backups for offline maps (the default is to disable backups)
  • MBXRasterTileOverlay's delegate property is weird. Make it normal.
  • MBXOfflineMapDownloader's delegate property is weird. Make it normal.
  • Make sure alloc/dealloc is solid for offline tile blob data coming from sqlite!

Activity

  1. ghost added this to the 0.3.0 milestone on Apr 22, 2014
  2. ghost added a commit that references this issue on Apr 23, 2014
  3. incanus commented on Apr 23, 2014

    @incanus
    Contributor

    Carryover of comment from #73


    This seems really well thought-out, @wsnook! I can't possibly hope to totally grok 65 commits and 32 changed files with 4,961 additions and 5 deletions just yet, particularly the whole functionality of MBXOfflineMapDownloader and its dual queue system, but here's how I see things proceeding:

    1. We address some more important comments below leading up to / when we voice Tuesday.
    2. We consider some other comments, more as backburner things that we can discuss on GitHub.
    3. We squash these into a new commit or handful of commits and open a pull request for more in-depth review and testing, getting it into master for some testing before release of 0.3.0.

    Main comments (voice)

    • Overall, and I mean this from a general "Mapbox how we do it" angle, it would help in future if you could more clearly highlight how to test the new functionality. I'm able to read through all the source myself and figure it out, but it takes a while and having a nice "run this app and press X button" comment would really help before I dive all in, since I've been away from these for some weeks / never used your example app directly anyway.
    • Related to the above, we need to clean up all the v030 stuff and just make the final proposed-merge branch reflect the state that master should be. In a branch, don't be shy about blowing away our current view controller/sample app/whatever. Branches are cheap and non-permanent.
    • If I'm understanding things properly, MBXOfflineMapDatabase instances, though referenced by the MBXOfflineMapDownloader and used as arguments by the delegate methods and -removeOfflineMapDatabase:, are meant to be opaque, "private" items. We should consider making all the methods and most/all of the properties on MBXOfflineMapDatabase private, with a category inside MBXOfflineMapDownloader / any other class that needs to use them directly. That is to say the "public" should never be calling these methods. As a descendent of NSObject, too, you can throw an exception inside of a declared -init to discourage such direct use. Otherwise, believe me, it's gonna happen / generate support inquiries.
    • Why is the delegate passed in -[MBXRasterTileOverlay initWithOfflineMapDatabase:delegate:]? How is this different from instantiating with a mapID? I'm asking both out of implementation curiosity but also as a future potential confused user of the API.

    Minor comments (online)

    • Properties like these should be more declarative and explain what they are for. metadata says "data structure" to me, not a BOOL value. Similar for markers, which says "image data or GeoJSON", not a boolean value. Probably something like hasMetadata? This is especially confusing when reading code like
      if(metadata)
      {
      [self asyncLoadMetadata];
      }
      else
      {
      _didFinishLoadingMetadata = YES;
      }
      where it's not really obvious what's happening. Does metadata = YES mean that metadata is not loaded?
    • Thinking ahead to how MBXOfflineMapDatabase will be used, could we maybe take -initWithContentsOfFile: one step further as we do over in https://github.com/mapbox/mapbox-ios-sdk/blob/3a1835bc8871dfba53befa20b41bddfdf1f4ca33/MapView/Map/RMMBTilesSource.h#L53-L63. These examples allow the user to specify a bundle resource or even just the first part of the filename (assuming .mbtiles) and the framework does the rest. Similarly, for offline map databases, these are basically always going to be in the app jail and either in the documents folder or the caches folder. I would recommend some default, but changeable, file extension (.mboffline?) perhaps before your .partial/.complete or even nothing appended to .mboffline in place of .complete, and then something like -initWithDatabaseName:inDocuments:, the latter argument being a BOOL defaulting to YES.
    • Related to the above, we should make iCloud backup configurable (
      // Make sure the offline map directory exists and that it will be excluded from iCloud backups
      ) per our discussions in Exclude db cache from iCloud backup, with option to include DEPRECATED-mapbox-ios-sdk#410. Defaulting as you've done but with the ability to change seems like good practice.
    • I like how the user agent for background downloads is differentiated (
      #if TARGET_OS_IPHONE
      userAgent = [NSString stringWithFormat:@"MBXMapKit (%@/%@) -- offline map", [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion]];
      #else
      userAgent = [NSString stringWithFormat:@"MBXMapKit (OS X/%@) -- offline map", [[NSProcessInfo processInfo] operatingSystemVersionString]];
      #endif
      ) but we should allow customization there, as well as setting it in one place for all uses of the SDK to avoid code duplication. The iOS SDK has a good model for this now in https://github.com/mapbox/mapbox-ios-sdk/blob/3a1835bc8871dfba53befa20b41bddfdf1f4ca33/MapView/Map/RMConfiguration.h#L52. It's just crazy simple there, as it should be.
    • Inside of -completeDatabaseAndInstantiateOfflineMapWithError: the idea of moving a file from a background thread (albeit supposedly a single-concurrency one) is kind of gross to me. Maybe an assert or dispatch_sync() to main queue there? Just something that ensures that the -setMaxConcurrentOperationCount:1 has happened elsewhere rather than implicitly linking these by intent, which will eventually be lost to the sands of time.
    • Why isn't -[MBXOfflineMapDownloader delegate] a property as is custom? Why is this write-only? That's weird for a delegate.
  4. ghost added a commit that references this issue on Apr 23, 2014
  5. incanus commented on Apr 23, 2014

    @incanus
    Contributor

    I am open to suggestions about how and where to draw the lines about attempting to enforce Java style public/private/protected stuff which isn't supported in the same way by objective c.

    You could always try this, which is a compiler hint, but still:

    http://www.nscrypto.com/blog/2013/05/14/at-private-instance-variables-in-objective-c/

    I'm open to alternate approaches which account for the let's-not-crash-the-app concern.

    The code smell for me here is that setting/unsetting or having/not having a delegate shouldn't 1) be required or 2) cause any sort of instability. Even if delegate methods are marked @required, a delegate is an opt-in sort of "notify me" construct. Contrast with UITableViewDataSource, which is 1) required and 2) still allowed to be set after instantiation, though in the same pass of the run loop.

    could we maybe take -initWithContentsOfFile: one step further

    Disregard this -- you are right in that a user should only be able to obtain an offline database through the methods, not by name.

    Attempting to make something for moving offline map databases between devices using iCloud seems like it would quickly run afoul of both Apple's storage guidelines

    I can see and have seen cases where offline downloads will be considered "documents" that a user possibly paid for the rights to download and thus should be backed up, even if they could re-download them in future. It's up to the dev to argue this point with Apple, but we want to technically accommodate them, IMHO.

    Re: the GCD/operation queue stuff, don't worry about it. It was just a suggestion for a check on the developer, but based on our voice yesterday I think there's enough of this going on that if we ensure it works as a whole we don't have to get to these sorts of fine details.

  6. ghost added a commit that references this issue on Apr 23, 2014
  7. incanus commented on Apr 23, 2014

    @incanus
    Contributor

    That's pretty good, but you could just as soon do (from https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Exceptions/Tasks/RaisingExceptions.html):

    NSException* myException = [NSException
            exceptionWithName:@"FileNotFoundException"
            reason:@"File Not Found on System"
            userInfo:nil];
    @throw myException;
    // [myException raise]; /* equivalent to above directive */
  8. incanus commented on Apr 23, 2014

    @incanus
    Contributor

    Pretty sure iCloud backups are device-specific. The only way to restore is to to wipe a device and apply a backup set, so effectively I think this is kosher. It could be another device, but I doubt anyone's doing this for fun or profit.

  9. ghost added a commit that references this issue on Apr 23, 2014
  10. 12 remaining items

  11. ghost added a commit that references this issue on Apr 28, 2014
  12. ghost added a commit that references this issue on Apr 28, 2014
  13. ghost added a commit that references this issue on Apr 28, 2014
  14. ghost added a commit that references this issue on Apr 28, 2014
  15. ghost added a commit that references this issue on Apr 29, 2014
  16. ghost added a commit that references this issue on Apr 30, 2014
  17. ghost added a commit that references this issue on Apr 30, 2014
  18. ghost added a commit that references this issue on Apr 30, 2014
  19. ghost added a commit that references this issue on Apr 30, 2014
  20. incanus commented on May 1, 2014

    @incanus
    Contributor

    #81 merged.

  21. vinod1988 commented on Feb 18, 2015

    @vinod1988

    Hi mapbox team,

    I am facing the issue in my app, when the user come instant online we got the following assertion error,
    This is random behaviour, Please guide me how can i resolve this issue.

    Console message:
    Assertion failed: (_activeDataSessionTasks > 0), function -[MBXOfflineMapDownloader sqliteSaveDownloadedData:forURL:], file /Users/vinod/VINOD/RAW/PROJECTS/AGRALOGICS/SOURCE_CODE/agls-grower-app-ios/Agralogic/ThirdParty/MBXMapKit/MBXOfflineMapDownloader.m, line 442.

    Mapbox library assertion break:

    #pragma mark - Implementation: sqlite stuff

    • (void)sqliteSaveDownloadedData:(NSData *)data forURL:(NSURL *)url
      {
      assert(![NSThread isMainThread]);
      assert(_activeDataSessionTasks > 0);

    Class name: MBXOfflineMapDownloader.

    Please help me
    Thanks in advance

  22. incanus commented on Feb 18, 2015

    @incanus
    Contributor

    @vinod1988 It sounds like you might be trying to begin an offline map download without checking whether there is currently one in progress. Are you maybe kicking off a download resume yourself, when the library is also doing this automatically?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions