summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2015-05-20 10:45:26 -0700
committerMinh Nguyễn <mxn@1ec5.org>2015-05-20 10:45:26 -0700
commit9a57464f823b36dc0c7b0db75f742a40513ffc87 (patch)
tree52f950a58499014d2557494016aa677b54b724e6
parenta04703e2d59ccedf32ef9bbd22169640a5aeec50 (diff)
downloadqtlocation-mapboxgl-9a57464f823b36dc0c7b0db75f742a40513ffc87.tar.gz
Removed accessToken from MGLMapView public API
With helpful instructions for migrating to Info.plist or the `MGLAccountManager` API.
-rw-r--r--include/mbgl/ios/MGLMapView.h27
-rw-r--r--platform/ios/MGLMapView.mm28
2 files changed, 23 insertions, 32 deletions
diff --git a/include/mbgl/ios/MGLMapView.h b/include/mbgl/ios/MGLMapView.h
index 9d7b5c9019..2d6589bf0d 100644
--- a/include/mbgl/ios/MGLMapView.h
+++ b/include/mbgl/ios/MGLMapView.h
@@ -20,30 +20,25 @@ 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. */
+/** Initializes and returns a newly allocated map view with the specified frame and the default style.
+* @param frame The frame for the view, measured in points.
+* @return An initialized map view or `nil` if the map view couldn’t be created. */
- (instancetype)initWithFrame:(CGRect)frame;
+- (instancetype)initWithFrame:(CGRect)frame accessToken:(NSString *)accessToken __attribute__((unavailable("Use -initWithFrame:. Set MGLMapboxAccessToken in the Info.plist or call +[MGLAccountManager setAccessToken:].")));
-/** 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.
-* @return An initialized map view, or `nil` if the map view was unable to be initialized. */
-- (instancetype)initWithFrame:(CGRect)frame accessToken:(NSString *)accessToken;
-
-/** Initialize a map view with a given frame, access token, and style URL.
- * @param frame The frame with which to initialize the map view.
- * @param accessToken A Mapbox API access token.
- * @param styleURL The map style URL to use. Can be either an HTTP/HTTPS URL or a Mapbox map ID style URL (`mapbox://<user.style>`).
- * @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;
+/** Initializes and returns a newly allocated map view with the specified frame and style URL.
+* @param frame The frame for the view, measured in points.
+* @param styleURL The map style URL to use. Can be either an HTTP/HTTPS URL or a Mapbox map ID style URL (`mapbox://<user.style>`).
+* @return An initialized map view or `nil` if the map view couldn’t be created. */
+- (instancetype)initWithFrame:(CGRect)frame styleURL:(NSURL *)styleURL;
+- (instancetype)initWithFrame:(CGRect)frame accessToken:(NSString *)accessToken styleURL:(NSURL *)styleURL __attribute__((unavailable("Use -initWithFrame:styleURL:. Set MGLMapboxAccessToken in the Info.plist or call +[MGLAccountManager setAccessToken:].")));
#pragma mark - Authorizing Access
/** @name Authorizing Access */
/** Mapbox API access token for the map view. */
-@property (nonatomic) NSString *accessToken;
+@property (nonatomic) NSString *accessToken __attribute__((unavailable("Use +[MGLAccountManager accessToken] and +[MGLAccountManager setAccessToken:].")));
#pragma mark - Managing Constraints
diff --git a/platform/ios/MGLMapView.mm b/platform/ios/MGLMapView.mm
index 4be5d20d27..cb89c58d46 100644
--- a/platform/ios/MGLMapView.mm
+++ b/platform/ios/MGLMapView.mm
@@ -113,25 +113,18 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
if (self && [self commonInit])
{
self.styleURL = nil;
- self.accessToken = [MGLAccountManager accessToken];
return self;
}
return nil;
}
-- (instancetype)initWithFrame:(CGRect)frame accessToken:(NSString *)accessToken
-{
- return [self initWithFrame:frame accessToken:accessToken styleURL:nil];
-}
-
-- (instancetype)initWithFrame:(CGRect)frame accessToken:(NSString *)accessToken styleURL:(NSURL *)styleURL
+- (instancetype)initWithFrame:(CGRect)frame styleURL:(NSURL *)styleURL
{
self = [super initWithFrame:frame];
if (self && [self commonInit])
{
- self.accessToken = accessToken;
self.styleURL = styleURL;
}
@@ -153,19 +146,18 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
- (NSString *)accessToken
{
- NSString *accessToken = @(_mbglMap->getAccessToken().c_str()).mgl_stringOrNilIfEmpty;
- return accessToken ? accessToken : [MGLAccountManager accessToken];
+ NSAssert(NO, @"-[MGLMapView accessToken] has been removed. Use +[MGLAccountManager accessToken] or get MGLMapboxAccessToken from the Info.plist.");
+ return nil;
}
- (void)setAccessToken:(NSString *)accessToken
{
- _mbglMap->setAccessToken(accessToken ? (std::string)[accessToken UTF8String] : "");
- [MGLAccountManager setAccessToken:accessToken.mgl_stringOrNilIfEmpty];
+ NSAssert(NO, @"-[MGLMapView setAccessToken:] has been replaced by +[MGLAccountManager setAccessToken:].\n\nIf you previously set this access token in a storyboard inspectable, select the MGLMapView in Interface Builder and delete the “accessToken” entry from the User Defined Runtime Attributes section of the Identity inspector. Then go to the Info.plist file and set MGLMapboxAccessToken to “%@”.", accessToken);
}
+ (NSSet *)keyPathsForValuesAffectingStyleURL
{
- return [NSSet setWithObjects:@"mapID", @"accessToken", nil];
+ return [NSSet setWithObjects:@"mapID", nil];
}
- (NSURL *)styleURL
@@ -274,6 +266,10 @@ std::chrono::steady_clock::duration secondsAsDuration(float duration)
}
_mbglMap->resize(self.bounds.size.width, self.bounds.size.height, _glView.contentScaleFactor);
+ // mbgl::Map keeps its own copy of the access token.
+ NSString *accessToken = [MGLAccountManager accessToken];
+ _mbglMap->setAccessToken(accessToken ? (std::string)[accessToken UTF8String] : "");
+
// Notify map object when network reachability status changes.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged:)
@@ -1557,7 +1553,7 @@ CLLocationCoordinate2D latLngToCoordinate(mbgl::LatLng latLng)
+ (NSSet *)keyPathsForValuesAffectingMapID
{
- return [NSSet setWithObjects:@"styleURL", @"accessToken", nil];
+ return [NSSet setWithObjects:@"styleURL", nil];
}
- (NSString *)mapID
@@ -2495,7 +2491,7 @@ CLLocationCoordinate2D latLngToCoordinate(mbgl::LatLng latLng)
self.layer.borderColor = [UIColor colorWithWhite:184/255. alpha:1].CGColor;
self.layer.borderWidth = 1;
- if (self.accessToken)
+ if ([MGLAccountManager accessToken])
{
self.layer.backgroundColor = [UIColor colorWithRed:59/255.
green:178/255.
@@ -2560,7 +2556,7 @@ CLLocationCoordinate2D latLngToCoordinate(mbgl::LatLng latLng)
// More explanation
UILabel *explanationLabel2 = [[UILabel alloc] init];
- explanationLabel2.text = @"and enter it into the Access Token field in the Attributes inspector or in an MGLMapboxAccessToken entry in the Info.plist file.";
+ explanationLabel2.text = @"and set it as the value of MGLMapboxAccessToken in the Info.plist file.";
explanationLabel2.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
explanationLabel2.numberOfLines = 0;
explanationLabel2.translatesAutoresizingMaskIntoConstraints = NO;