diff --git a/.travis.yml b/.travis.yml index b2dae3cf0..2f50535cc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,35 +31,35 @@ matrix: - os: linux env: FLAVOR=android ANDROID_ABI=arm-v7 BUILDTYPE=Release android: - components: [ 'build-tools-22.0.0', 'android-22', 'extra' ] + components: [ 'build-tools-22.0.1', 'android-22', 'extra' ] addons: apt: packages: [ 'lib32stdc++6' ] - os: linux env: FLAVOR=android ANDROID_ABI=arm-v7 BUILDTYPE=Debug android: - components: [ 'build-tools-22.0.0', 'android-22', 'extra' ] + components: [ 'build-tools-22.0.1', 'android-22', 'extra' ] addons: apt: packages: [ 'lib32stdc++6' ] - os: linux env: FLAVOR=android ANDROID_ABI=arm-v8 BUILDTYPE=Release android: - components: [ 'build-tools-22.0.0', 'android-22', 'extra' ] + components: [ 'build-tools-22.0.1', 'android-22', 'extra' ] addons: apt: packages: [ 'lib32stdc++6' ] - os: linux env: FLAVOR=android ANDROID_ABI=x86 BUILDTYPE=Release android: - components: [ 'build-tools-22.0.0', 'android-22', 'extra' ] + components: [ 'build-tools-22.0.1', 'android-22', 'extra' ] addons: apt: packages: [ 'lib32stdc++6' ] - os: linux env: FLAVOR=android ANDROID_ABI=mips BUILDTYPE=Release android: - components: [ 'build-tools-22.0.0', 'android-22', 'extra' ] + components: [ 'build-tools-22.0.1', 'android-22', 'extra' ] addons: apt: packages: [ 'lib32stdc++6' ] diff --git a/README.md b/README.md index 8b5dd5760..8f2dd6db2 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,20 @@ Target OS X: 10.9+ ## iOS -If you merely want to install the library for iOS and try it out as an Objective-C consumer: +### Use + +#### CocoaPods + +CocoaPods is preferred. As of yet, Mapbox GL isn't in the global specs repo, but you can use it like so in your `Podfile`: + +```ruby +use_frameworks! +pod 'MapboxGL', :podspec => 'https://raw.githubusercontent.com/mapbox/mapbox-gl-native/master/ios/MapboxGL.podspec' +``` + +Once the library stabilizes, a mere `pod 'MapboxGL'` will work. + +#### Manually 0. Use [Homebrew](http://brew.sh/) to install Boost headers and [appledoc](http://gentlebytes.com/appledoc/): `brew install boost appledoc`. 1. Run `make ipackage`. The packaging script will produce the statically-linked `libMapboxGL.a`, `MapboxGL.bundle` for resources, a `Headers` folder, and a `Docs` folder with HTML API documentation. @@ -67,6 +80,8 @@ If you merely want to install the library for iOS and try it out as an Objective 5. [Set the Mapbox API access token](#mapbox-api-access-tokens). 6. `#import "MapboxGL.h"` +### Development + If you want to build from source and/or contribute to development of the project, run `make iproj`, which will create and open an Xcode project which can build the entire library from source as well as an Objective-C test app. If you don't have an Apple Developer account, change the destination from "My Mac" to a simulator such as "iPhone 6" before you run and build the app. You can run `make itest` to run the included integration tests. Requires `gem install xcpretty`. If you want to run the tests in Xcode instead, first `make ipackage` to create a local static library version, then open `test/ios/ios-tests.xcodeproj`, and lastly `Command + U` on the `Mapbox GL Tests` application target. diff --git a/android/java/MapboxGLAndroidSDK/build.gradle b/android/java/MapboxGLAndroidSDK/build.gradle index 901aa6d9d..f0659b8c7 100644 --- a/android/java/MapboxGLAndroidSDK/build.gradle +++ b/android/java/MapboxGLAndroidSDK/build.gradle @@ -3,7 +3,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:1.1.3' + classpath 'com.android.tools.build:gradle:1.2.2' classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.0' } } @@ -29,9 +29,9 @@ repositories { dependencies { compile 'commons-validator:commons-validator:1.4.1' - compile 'com.android.support:support-annotations:22.0.0' - compile 'com.android.support:support-v4:22.0.0' - compile 'com.squareup.okhttp:okhttp:2.2.0' + compile 'com.android.support:support-annotations:22.1.1' + compile 'com.android.support:support-v4:22.1.1' + compile 'com.squareup.okhttp:okhttp:2.3.0' } android { diff --git a/android/java/MapboxGLAndroidSDK/gradle.properties b/android/java/MapboxGLAndroidSDK/gradle.properties index 79e2dadca..8ba98ea4f 100644 --- a/android/java/MapboxGLAndroidSDK/gradle.properties +++ b/android/java/MapboxGLAndroidSDK/gradle.properties @@ -14,7 +14,7 @@ POM_DEVELOPER_NAME=Mapbox ANDROID_MIN_SDK=8 ANDROID_BUILD_TARGET_SDK_VERSION=22 -ANDROID_BUILD_TOOLS_VERSION=22.0.0 +ANDROID_BUILD_TOOLS_VERSION=22.0.1 ANDROID_BUILD_SDK_VERSION=22 POM_NAME=Mapbox GL Android SDK diff --git a/android/java/MapboxGLAndroidSDKTestApp/build.gradle b/android/java/MapboxGLAndroidSDKTestApp/build.gradle index 7cdd4fc91..5f2db91d7 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/build.gradle +++ b/android/java/MapboxGLAndroidSDKTestApp/build.gradle @@ -3,7 +3,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:1.1.3' + classpath 'com.android.tools.build:gradle:1.2.2' classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.0' } } @@ -31,7 +31,7 @@ gradle.projectsEvaluated { android { compileSdkVersion 22 - buildToolsVersion "22.0.0" + buildToolsVersion "22.0.1" repositories { mavenCentral() @@ -74,9 +74,9 @@ dependencies { compile(project(':MapboxGLAndroidSDK')) { transitive = true } - compile 'com.android.support:support-annotations:22.0.0' - compile 'com.android.support:support-v4:22.0.0' - compile 'com.android.support:appcompat-v7:22.0.0' + compile 'com.android.support:support-annotations:22.1.1' + compile 'com.android.support:support-v4:22.1.1' + compile 'com.android.support:appcompat-v7:22.1.1' compile 'com.mapzen.android:lost:1.0.0' } diff --git a/gyp/platform-ios.gypi b/gyp/platform-ios.gypi index d23192c8c..1f96f9470 100644 --- a/gyp/platform-ios.gypi +++ b/gyp/platform-ios.gypi @@ -25,6 +25,8 @@ '../platform/ios/MGLMapView.mm', '../platform/ios/MGLFileCache.h', '../platform/ios/MGLFileCache.mm', + '../include/mbgl/ios/MGLAccountManager.h', + '../platform/ios/MGLAccountManager.m', '../include/mbgl/ios/MGLAnnotation.h', '../include/mbgl/ios/MGLUserLocation.h', '../platform/ios/MGLUserLocation_Private.h', diff --git a/include/mbgl/ios/MGLAccountManager.h b/include/mbgl/ios/MGLAccountManager.h new file mode 100644 index 000000000..c1b7406b9 --- /dev/null +++ b/include/mbgl/ios/MGLAccountManager.h @@ -0,0 +1,6 @@ +@interface MGLAccountManager : NSObject + ++ (void) setAccessToken:(NSString *) accessToken; ++ (NSString *) accessToken; + +@end \ No newline at end of file diff --git a/include/mbgl/ios/MGLMapView.h b/include/mbgl/ios/MGLMapView.h index 7c757ba93..9d7b5c901 100644 --- a/include/mbgl/ios/MGLMapView.h +++ b/include/mbgl/ios/MGLMapView.h @@ -20,6 +20,11 @@ IB_DESIGNABLE /** @name Initializing a Map View */ +/** Initialize a map view with the default style, given frame, and access token set in MapboxGL singleton. +* @param frame The frame with which to initialize the map view. +* @return An initialized map view, or `nil` if the map view was unable to be initialized. */ +- (instancetype)initWithFrame:(CGRect)frame; + /** Initialize a map view with the default style and a given frame and access token. * @param frame The frame with which to initialize the map view. * @param accessToken A Mapbox API access token. @@ -33,8 +38,6 @@ IB_DESIGNABLE * @return An initialized map view, or `nil` if the map view was unable to be initialized. */ - (instancetype)initWithFrame:(CGRect)frame accessToken:(NSString *)accessToken styleURL:(NSURL *)styleURL; -- (instancetype)initWithFrame:(CGRect)frame __attribute__((unavailable("Instantiating an MGLMapView requires setting a style and/or an access token."))); - #pragma mark - Authorizing Access /** @name Authorizing Access */ diff --git a/include/mbgl/ios/MapboxGL.h b/include/mbgl/ios/MapboxGL.h index c32915bc7..34e080a51 100644 --- a/include/mbgl/ios/MapboxGL.h +++ b/include/mbgl/ios/MapboxGL.h @@ -2,3 +2,4 @@ #import "MGLMapView.h" #import "MGLTypes.h" #import "MGLUserLocation.h" +#import "MGLAccountManager.h" \ No newline at end of file diff --git a/include/mbgl/ios/MGLMapView_Private.h b/include/mbgl/ios/private/MGLMapView_Private.h similarity index 100% rename from include/mbgl/ios/MGLMapView_Private.h rename to include/mbgl/ios/private/MGLMapView_Private.h diff --git a/include/mbgl/storage/request.hpp b/include/mbgl/storage/request.hpp index a01808ce8..5d979a281 100644 --- a/include/mbgl/storage/request.hpp +++ b/include/mbgl/storage/request.hpp @@ -19,8 +19,6 @@ namespace mbgl { class Response; class Request : private util::noncopyable { - MBGL_STORE_THREAD(tid) - public: using Callback = std::function; Request(const Resource &resource, uv_loop_t *loop, Callback callback); diff --git a/ios/MapboxGL.podspec b/ios/MapboxGL.podspec index ad5470020..3529e3c00 100644 --- a/ios/MapboxGL.podspec +++ b/ios/MapboxGL.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |m| m.name = 'MapboxGL' - m.version = '0.2.19' + m.version = '0.2.21' m.summary = 'Open source vector map solution for iOS with full styling capabilities.' m.description = 'Open source OpenGL-based vector map solution for iOS with full styling capabilities and Cocoa bindings.' @@ -26,7 +26,6 @@ Pod::Spec.new do |m| m.resource_bundle = { 'MapboxGL' => 'MapboxGL.bundle/*' } m.vendored_library = 'libMapboxGL.a' - m.frameworks = 'CoreLocation', 'CoreTelephony', 'GLKit', 'ImageIO', 'MobileCoreServices', 'QuartzCore', 'SystemConfiguration' m.libraries = 'c++', 'sqlite3', 'z' m.xcconfig = { 'OTHER_CPLUSPLUSFLAGS' => '-std=gnu++11 -stdlib=libc++' } diff --git a/ios/app/MBXAppDelegate.m b/ios/app/MBXAppDelegate.m index f2ef69ec6..90c552aba 100644 --- a/ios/app/MBXAppDelegate.m +++ b/ios/app/MBXAppDelegate.m @@ -1,11 +1,29 @@ #import "MBXAppDelegate.h" #import "MBXViewController.h" +#import +#import #import @implementation MBXAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Set Access Token + NSString *accessToken = [[NSProcessInfo processInfo] environment][@"MAPBOX_ACCESS_TOKEN"]; + if (accessToken) { + // Store to preferences so that we can launch the app later on without having to specify + // token. + [[NSUserDefaults standardUserDefaults] setObject:accessToken forKey:@"access_token"]; + } else { + // Try to retrieve from preferences, maybe we've stored them there previously and can reuse + // the token. + accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"access_token"]; + } + if ( ! accessToken) NSLog(@"No access token set. Mapbox vector tiles won't work."); + + // Start Mapbox GL SDK + [MGLAccountManager setAccessToken:accessToken]; + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[MBXViewController new]]; [self.window makeKeyAndVisible]; diff --git a/ios/app/MBXViewController.mm b/ios/app/MBXViewController.mm index 98c8e016d..eb77a2ec8 100644 --- a/ios/app/MBXViewController.mm +++ b/ios/app/MBXViewController.mm @@ -52,20 +52,7 @@ mbgl::Settings_NSUserDefaults *settings = nullptr; { [super viewDidLoad]; - NSString *accessToken = [[NSProcessInfo processInfo] environment][@"MAPBOX_ACCESS_TOKEN"]; - if (accessToken) { - // Store to preferences so that we can launch the app later on without having to specify - // token. - [[NSUserDefaults standardUserDefaults] setObject:accessToken forKey:@"access_token"]; - } else { - // Try to retrieve from preferences, maybe we've stored them there previously and can reuse - // the token. - accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"access_token"]; - } - - if ( ! accessToken) NSLog(@"No access token set. Mapbox vector tiles won't work."); - - self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds accessToken:accessToken]; + self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds]; self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; self.mapView.showsUserLocation = YES; self.mapView.delegate = self; diff --git a/ios/benchmark/MBXBenchViewController.mm b/ios/benchmark/MBXBenchViewController.mm index 0ac667527..1876a0c54 100644 --- a/ios/benchmark/MBXBenchViewController.mm +++ b/ios/benchmark/MBXBenchViewController.mm @@ -1,7 +1,7 @@ #import "MBXBenchViewController.h" #import -#import +#import #include "locations.hpp" diff --git a/ios/docs/install_docs.sh b/ios/docs/install_docs.sh index c74c6bcd2..df1d366e6 100755 --- a/ios/docs/install_docs.sh +++ b/ios/docs/install_docs.sh @@ -17,4 +17,5 @@ appledoc \ --project-company Mapbox \ --create-docset \ --company-id com.mapbox \ + --ignore ../../include/mbgl/ios/private \ ../../include/mbgl/ios diff --git a/platform/ios/MGLAccountManager.m b/platform/ios/MGLAccountManager.m new file mode 100644 index 000000000..b1a80fd6a --- /dev/null +++ b/platform/ios/MGLAccountManager.m @@ -0,0 +1,53 @@ +#import + +#import "MGLAccountManager.h" +#import "NSProcessInfo+MGLAdditions.h" +#import "MGLMapboxEvents.h" + +@interface MGLAccountManager() + +@property (atomic) NSString *accessToken; + +@end + + +@implementation MGLAccountManager + +static MGLAccountManager *_sharedManager; + +// Can be called from any thread. +// ++ (instancetype) sharedInstance { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + if ( ! NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent) { + void (^setupBlock)() = ^{ + _sharedManager = [[self alloc] init]; + }; + if ( ! [[NSThread currentThread] isMainThread]) { + dispatch_sync(dispatch_get_main_queue(), ^{ + setupBlock(); + }); + } + else { + setupBlock(); + } + } + }); + return _sharedManager; +} + ++ (void) setAccessToken:(NSString *) accessToken { + [[MGLAccountManager sharedInstance] setAccessToken:accessToken]; + + // Update MGLMapboxEvents + // NOTE: This is (likely) the initial setup of MGLMapboxEvents + [MGLMapboxEvents setToken:accessToken]; +} + ++ (NSString *) accessToken { + return [MGLAccountManager sharedInstance].accessToken; +} + + +@end \ No newline at end of file diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm index 3ea7c0cec..9fd94fc7b 100644 --- a/platform/ios/MGLMapView.mm +++ b/platform/ios/MGLMapView.mm @@ -28,6 +28,7 @@ #import "SMCalloutView.h" #import "MGLMapboxEvents.h" +#import "MapboxGL.h" #import @@ -109,6 +110,7 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration) if (self && [self commonInit]) { self.styleURL = nil; + self.accessToken = [MGLAccountManager accessToken]; return self; } diff --git a/scripts/ios/install.sh b/scripts/ios/install.sh index 8da90ec3b..274557c5d 100755 --- a/scripts/ios/install.sh +++ b/scripts/ios/install.sh @@ -15,4 +15,7 @@ gem install xcpretty --no-rdoc --no-ri --no-document --quiet mapbox_time "install_recent_git" \ brew install git +mapbox_time "install_awscli" \ +brew install awscli + mkdir -p ${KIF_SCREENSHOTS} diff --git a/scripts/ios/package.sh b/scripts/ios/package.sh index dd9e216ac..0f190d45b 100755 --- a/scripts/ios/package.sh +++ b/scripts/ios/package.sh @@ -81,7 +81,9 @@ echo "Created ${OUTPUT}/static/lib${NAME}.a" step "Copying Headers..." mkdir -p "${OUTPUT}/static/Headers" -cp -pv include/mbgl/ios/* "${OUTPUT}/static/Headers" +for i in `ls -R include/mbgl/ios | grep -vi private`; do + cp -pv include/mbgl/ios/$i "${OUTPUT}/static/Headers" +done # Manually create resource bundle. We don't use a GYP target here because of @@ -109,6 +111,3 @@ appledoc \ --no-install-docset \ --company-id com.mapbox \ include/mbgl/ios -cd ${DOCS_OUTPUT} -ln -s html/index.html -cd ${OLDPWD} diff --git a/src/mbgl/map/environment.cpp b/src/mbgl/map/environment.cpp index dd6c1f193..5857d4bdf 100644 --- a/src/mbgl/map/environment.cpp +++ b/src/mbgl/map/environment.cpp @@ -128,7 +128,6 @@ void Environment::requestAsync(const Resource& resource, Request* Environment::request(const Resource& resource, std::function callback) { - assert(currentlyOn(ThreadType::Map)); return fileSource.request(resource, util::RunLoop::current.get()->get(), std::move(callback)); } diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index 4e0a04472..2352e09c2 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include @@ -62,8 +61,8 @@ MapContext::~MapContext() { // Explicit resets currently necessary because these abandon resources that need to be // cleaned up by env.performCleanup(); + resourceLoader.reset(); style.reset(); - sprite.reset(); painter.reset(); texturePool.reset(); lineAtlas.reset(); @@ -124,24 +123,10 @@ void MapContext::setStyleJSON(const std::string& json, const std::string& base) loadStyleJSON(json, base); } -util::ptr MapContext::getSprite() { - assert(Environment::currentlyOn(ThreadType::Map)); - const float pixelRatio = transformState.getPixelRatio(); - const std::string &sprite_url = style->getSpriteURL(); - if (!sprite || !sprite->hasPixelRatio(pixelRatio)) { - sprite = std::make_shared(sprite_url, pixelRatio, env, [this] { - assert(Environment::currentlyOn(ThreadType::Map)); - triggerUpdate(); - }); - } - - return sprite; -} - void MapContext::loadStyleJSON(const std::string& json, const std::string& base) { assert(Environment::currentlyOn(ThreadType::Map)); - sprite.reset(); + resourceLoader.reset(); style.reset(); style = util::make_unique