[iOS SDK] How to integrate Mapbox into your Xcode project, for dummies.

As an iOS dummy i was, i downloaded the mapbox basic tutorial, built & ran it, and it worked perfectly. Now i was wondering how to integrate this example in an Xcode project that i start from zero.

After some research i discovered the way of doing it, and i made myself this little guide:

1.- In your new Xcode project, click on the main target, scroll to the bottom and you’ll find “Linked frameworks and libraries”. Click on the [+] button

Captura de pantalla 2014-08-06 a la(s) 17.09.18 

2.- Now click on Add other, and locate the “Mapbox.framework” file. A copy of it is located inside “mapbox-example-ios” folder.

3.- repeat steps 1 and 2 but now locating and including “libsqlite3.dylib”, “CoreLocation.framework“, and “QuartzCore.framework“. Click on the [+] button, and on the search box type each name, it will appear.

4.- Create a new objC class extending UIViewController. In its .h file, include the #import <Mapbox/Mapbox.h>, and implement the “RMMapViewDelegate” delegate.

#import <Mapbox/Mapbox.h>

@interface MyOfflineMapViewController : UIViewController<RMMapViewDelegate>
@end

5.- copy the .mbtiles map file by dragging and dropping it to the project folder in xcode. IMPORTANT: Do not forget to check “copy items into destination group’s folder”, and to mark all the targets before clicking finish!

Captura de pantalla 2014-08-06 a la(s) 17.11.56

*If you don’t do this, you will get this error: reason: ‘*** -[NSURL initFileURLWithPath:]: nil string parameter’ (luckily, Google searches arrive here and anyone finding this error can fix it)

6.- in the .m file, initialize the TilesSource and the MapView as its done in the Mapbox example

- (void)viewDidLoad
{
[super viewDidLoad];    
RMMBTilesSource *offlineSource = [[RMMBTilesSource alloc] initWithTileSetResource:@“mymbtilesmap" ofType:@"mbtiles"];
RMMapView *mapView = [[RMMapView alloc] initWithFrame:self.view.bounds andTilesource:offlineSource];
mapView.zoom = 2;
mapView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth
mapView.adjustTilesForRetinaDisplay = YES; // these tiles aren't designed specifically for retina, so make them legible
[self.view addSubview:mapView];
mapView.delegate  = self;
}

7.- Build and run your app, navigate to the offline map ViewController. Your map should be visible. Let me know any errors / issues in these instructions.

Advertisements

3 thoughts on “[iOS SDK] How to integrate Mapbox into your Xcode project, for dummies.

  1. Pingback: [iOS SDK] Creating my own offline map with Mapbox (.mbtiles format) | Mobile Dev Stories

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s