Xcode’s static library template comes with the -ObjC linker flag by default. Instead of removing that flag, this change removes the various imperfect workarounds we’ve been using to ensure that private SDK categories link. Given the size decrease in this static library since #2966 was fixed, we should have room to spare for the more straightforward approach. Moreover, an application that uses MGLMapView in a storyboard no longer needs to add -ObjC to the application target, which bloated the entire application, including other frameworks that had no need for -ObjC. -ObjC isn’t even needed for dynamic frameworks, and the OS X SDK is only built as a dynamic framework.
6.0 KiB
Integrating the Mapbox iOS SDK into your application
This document explains how to build a development version of Mapbox iOS SDK for the purpose of incorporating it into your own Cocoa Touch application.
Requirements
The Mapbox iOS SDK and iosapp demo application build against the iOS 7.0 SDK. They are intended to run on iOS 7.0 and above on the following devices and their simulators:
- iPhone 4S and above (5, 5c, 5s, 6, 6 Plus)
- iPad 2 and above (3, 4, Mini, Air, Mini 2, Air 2)
- iPod touch 5th generation and above
Build
-
Install jazzy for generating API documentation:
[sudo] gem install jazzy -
Install ios-sim version 3.2.0 (not any other version) for running
make test-ios:brew tap mapbox/homebrew-ios-sim-3 brew install mapbox/homebrew-ios-sim-3/ios-sim -
Run
make ipackage. The packaging script will produce abuild/ios/pkg/folder containing:
- a
dynamicfolder containing a dynamically-linked fat framework with debug symbols for devices and the iOS Simulator - a
staticfolder containing a statically-linked framework with debug symbols for devices and the iOS Simulator - a
documentationfolder with HTML API documentation - an example
Settings.bundlecontaining an optional Mapbox Telemetry opt-out setting
Install
There are a few ways to install the Mapbox iOS SDK:
CocoaPods
Currently, until #1437 is completed, to install a development version of Mapbox GL using CocoaPods you will need to build it from source manually per above.
-
Zip up the build product.
cd build/ios/pkg/ ZIP=mapbox-ios-sdk.zip rm -f ../${ZIP} zip -r ../${ZIP} * -
Customize
Mapbox-iOS-SDK.podspecto download this zip file.{...} m.source = { :http => "http://{...}/mapbox-ios-sdk.zip", :flatten => true } {...} -
Update your app's
Podfileto point to theMapbox-iOS-SDK.podspec.pod 'Mapbox-iOS-SDK', :podspec => 'http://{...}/Mapbox-iOS-SDK.podspec' -
Run
pod updateto grab the newly-built library.
Testing Pre-Releases with CocoaPods
To test pre-releases and/or betas, you can reference the pre-release like so in your Podfile:
pod 'Mapbox-iOS-SDK', podspec: 'https://raw.githubusercontent.com/mapbox/mapbox-gl-native/<insert branch or tag>/ios/Mapbox-iOS-SDK.podspec'
Dynamic framework
This is the recommended workflow for manually integrating the SDK into an application targeting iOS 8 and above:
-
Build from source manually per above.
-
Open the project editor and select your application target. Drag
build/ios/pkg/dynamic/Mapbox.frameworkinto the “Embedded Binaries” section of the General tab. (Don’t drag it into the “Linked Frameworks and Libraries” section; Xcode will add it there automatically.) In the sheet that appears, make sure “Copy items if needed” is checked, then click Finish. -
In the Build Phases tab, click the + button at the top and select “New Run Script Phase”. Enter the following code into the script text field:
bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mapbox.framework/strip-frameworks.sh"
(The last step, courtesy of Realm, is required for working around an iOS App Store bug when archiving universal binaries.)
Static framework
If your application targets iOS 7.x, you’ll need to install the static framework instead:
-
Build from source manually per above.
-
Drag the Mapbox.bundle and Mapbox.framework files in
build/ios/pkg/staticinto the Project navigator, checking "Copy items if needed". It should happen automatically, but ensure that:Mapbox.frameworkis listed in yourLink Binary With Librariesbuild phase.- Your Framework Search Paths (
FRAMEWORK_SEARCH_PATHS) build setting includes the directory that containsMapbox.framework. For most projects, the default value of$(inherited) $(PROJECT_DIR)should be sufficient. Mapbox.bundleis in your target's Copy Bundle Resources build phase.
-
Optional As noted in the documentation you may use the provided Settings.bundle to provide a Telemetry opt out for users. To use the provided file, drag the
Settings.bundlefile inbuild/ios/pkginto the Project navigator, checking "Copy items if needed". It should happen automatically, but ensure that:Settings.bundleis in your target's Copy Bundle Resources build phase.
-
Add the following Cocoa Touch frameworks and libraries to the “Linked Frameworks and Libraries” section:
GLKit.frameworkImageIO.frameworkMobileCoreServices.frameworkQuartzCore.frameworkSystemConfiguration.frameworklibc++.tbdlibsqlite3.tbdlibz.tbd
Use
-
Mapbox vector tiles require a Mapbox account and API access token. In the project editor, select the application target. In the Info tab, set
MGLMapboxAccessTokento your access token. You can obtain one from the Mapbox account page. -
In a XIB or storyboard, add a View and set its custom class to
MGLMapView. If you need to manipulate the map view programmatically, import theMapboxmodule (Swift) orMapbox.humbrella header (Objective-C), then connect the map view to a new outlet in your view controller class. The resulting outlet declaration should look something like:
// ViewController.m
#import <Mapbox/Mapbox.h>
@interface ViewController : UIViewController
@property (strong) IBOutlet MGLMapView *mapView;
@end
// ViewController.swift
import Mapbox
class ViewController: UIViewController {
@IBOutlet var mapView: MGLMapView!
}
Troubleshooting
On OS X, you can also try clearing the Xcode cache with make clear_xcode_cache.