Authored by Justin R. Miller

Merge branch 'develop' of github.com:mapbox/mapbox-ios-sdk into develop

... ... @@ -32,6 +32,7 @@
#import "RMCacheObject.h"
#import "RMCircle.h"
#import "RMCompositeSource.h"
#import "RMConfiguration.h"
#import "RMCoordinateGridSource.h"
#import "RMDatabaseCache.h"
#import "RMInteractiveSource.h"
... ...
... ... @@ -26,7 +26,9 @@
// POSSIBILITY OF SUCH DAMAGE.
#import "RMAbstractWebMapSource.h"
#import "RMTileCache.h"
#import "RMConfiguration.h"
#define HTTP_404_NOT_FOUND 404
... ... @@ -108,7 +110,7 @@
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:currentURL];
[request setTimeoutInterval:(self.requestTimeoutSeconds / (CGFloat)self.retryCount)];
tileData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
tileData = [NSURLConnection sendBrandedSynchronousRequest:request returningResponse:nil error:nil];
}
if (tileData)
... ... @@ -157,7 +159,7 @@
NSHTTPURLResponse *response = nil;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[URLs objectAtIndex:0]];
[request setTimeoutInterval:(self.requestTimeoutSeconds / (CGFloat)self.retryCount)];
image = [UIImage imageWithData:[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil]];
image = [UIImage imageWithData:[NSURLConnection sendBrandedSynchronousRequest:request returningResponse:&response error:nil]];
if (response.statusCode == HTTP_404_NOT_FOUND)
break;
... ...
... ... @@ -27,6 +27,8 @@
#import "RMBingSource.h"
#import "RMConfiguration.h"
@implementation RMBingSource
{
NSString *_mapsKey;
... ... @@ -78,7 +80,7 @@
NSURL *metadataURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://dev.virtualearth.net/REST/v1/Imagery/Metadata/%@?key=%@", imagerySetString, _mapsKey]];
NSData *metadataData = [NSData dataWithContentsOfURL:metadataURL];
NSData *metadataData = [NSData brandedDataWithContentsOfURL:metadataURL];
id metadata = [NSJSONSerialization JSONObjectWithData:metadataData options:0 error:nil];
... ...
... ... @@ -27,12 +27,52 @@
#import <UIKit/UIKit.h>
/** The RMConfiguration object is a shared instance of the configuration for the library. */
@interface RMConfiguration : NSObject
/** @name Accessing the Configuration */
/** Access the shared instance of the configuration.
* @return The shared configuration instance. */
+ (RMConfiguration *)configuration;
- (RMConfiguration *)initWithPath:(NSString *)path;
/** Access the disk- and memory-based cache configuration.
* @return A dictionary containing the cache configuration. */
- (NSDictionary *)cacheConfiguration;
/** @name Changing and Accessing a Custom User Agent */
/** Access and change the global user agent for HTTP requests using the library.
*
* If unset, defaults to `MapBox iOS SDK` followed by generic hardware model and software version information.
*
* Example: `MyMapApp/1.2` */
@property (nonatomic, retain) NSString *userAgent;
@end
#pragma mark -
@interface NSURLConnection (RMUserAgent)
+ (NSData *)sendBrandedSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse **)response error:(NSError **)error;
@end
#pragma mark -
@interface NSData (RMUserAgent)
+ (NSData *)brandedDataWithContentsOfURL:(NSURL *)aURL;
@end
#pragma mark -
@interface NSString (RMUserAgent)
+ (id)brandedStringWithContentsOfURL:(NSURL *)url encoding:(NSStringEncoding)enc error:(NSError **)error;
@end
... ...
... ... @@ -29,11 +29,54 @@
static RMConfiguration *RMConfigurationSharedInstance = nil;
@implementation NSURLConnection (RMUserAgent)
+ (NSData *)sendBrandedSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse **)response error:(NSError **)error
{
NSMutableURLRequest *newRequest = [NSMutableURLRequest requestWithURL:request.URL cachePolicy:request.cachePolicy timeoutInterval:request.timeoutInterval];
[newRequest setValue:[[RMConfiguration configuration] userAgent] forHTTPHeaderField:@"User-Agent"];
return [NSURLConnection sendSynchronousRequest:newRequest returningResponse:response error:error];
}
@end
#pragma mark -
@implementation NSData (RMUserAgent)
+ (NSData *)brandedDataWithContentsOfURL:(NSURL *)aURL
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:aURL];
[request setValue:[[RMConfiguration configuration] userAgent] forHTTPHeaderField:@"User-Agent"];
return [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
}
@end
#pragma mark -
@implementation NSString (RMUserAgent)
+ (id)brandedStringWithContentsOfURL:(NSURL *)url encoding:(NSStringEncoding)enc error:(NSError **)error
{
return [[self class] stringWithContentsOfURL:url encoding:enc error:error];
}
@end
#pragma mark -
@implementation RMConfiguration
{
id _propertyList;
}
@synthesize userAgent=_userAgent;
+ (RMConfiguration *)configuration
{
static dispatch_once_t onceToken;
... ... @@ -49,6 +92,8 @@ static RMConfiguration *RMConfigurationSharedInstance = nil;
if (!(self = [super init]))
return nil;
_userAgent = [[NSString stringWithFormat:@"MapBox iOS SDK (%@/%@)", [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion]] retain];
if (path == nil)
{
_propertyList = nil;
... ... @@ -77,6 +122,7 @@ static RMConfiguration *RMConfigurationSharedInstance = nil;
- (void)dealloc
{
[_propertyList release]; _propertyList = nil;
[_userAgent release];
[super dealloc];
}
... ...
... ... @@ -33,6 +33,8 @@
#import "RMInteractiveSource.h"
#import "RMConfiguration.h"
#import "FMDatabase.h"
#import "FMDatabaseQueue.h"
... ... @@ -542,7 +544,7 @@ RMTilePoint RMInteractiveSourceNormalizedTilePointForMapView(CGPoint point, RMMa
// get the data for this tile
//
NSData *gridData = [NSData dataWithContentsOfURL:[NSURL URLWithString:gridURLString]];
NSData *gridData = [NSData brandedDataWithContentsOfURL:[NSURL URLWithString:gridURLString]];
if (gridData)
{
... ...
... ... @@ -35,6 +35,7 @@
#import "RMMapView.h"
#import "RMPointAnnotation.h"
#import "RMConfiguration.h"
@interface RMMapBoxSource ()
... ... @@ -88,7 +89,7 @@
NSMutableString *jsonString = nil;
if (dataURL && (jsonString = [NSMutableString stringWithContentsOfURL:dataURL encoding:NSUTF8StringEncoding error:nil]) && jsonString)
if (dataURL && (jsonString = [NSMutableString brandedStringWithContentsOfURL:dataURL encoding:NSUTF8StringEncoding error:nil]) && jsonString)
{
if ([jsonString hasPrefix:@"grid("])
{
... ... @@ -148,7 +149,7 @@
options:NSAnchoredSearch & NSBackwardsSearch
range:NSMakeRange(0, [[referenceURL absoluteString] length])]];
if ([[referenceURL pathExtension] isEqualToString:@"json"] && (dataObject = [NSString stringWithContentsOfURL:referenceURL encoding:NSUTF8StringEncoding error:nil]) && dataObject)
if ([[referenceURL pathExtension] isEqualToString:@"json"] && (dataObject = [NSString brandedStringWithContentsOfURL:referenceURL encoding:NSUTF8StringEncoding error:nil]) && dataObject)
return [self initWithTileJSON:dataObject enablingDataOnMapView:mapView];
return nil;
... ...
... ... @@ -26,7 +26,9 @@
// POSSIBILITY OF SUCH DAMAGE.
#import "RMMarker.h"
#import "RMPixel.h"
#import "RMConfiguration.h"
@implementation RMMarker
... ... @@ -147,7 +149,7 @@
if ((image = [UIImage imageWithData:[NSData dataWithContentsOfFile:cachePath] scale:(useRetina ? 2.0 : 1.0)]) && image)
return [self initWithUIImage:image];
[[NSFileManager defaultManager] createFileAtPath:cachePath contents:[NSData dataWithContentsOfURL:imageURL] attributes:nil];
[[NSFileManager defaultManager] createFileAtPath:cachePath contents:[NSData brandedDataWithContentsOfURL:imageURL] attributes:nil];
return [self initWithUIImage:[UIImage imageWithData:[NSData dataWithContentsOfFile:cachePath] scale:(useRetina ? 2.0 : 1.0)]];
}
... ...