Skip to content

Commit 57a12b7

Browse files
committed
Ensure device id is indeed optional - nil wasn't being handled by NSDictionary
Ensure options allow for defaults and also set explicitly
1 parent d997dc7 commit 57a12b7

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

CloudSight/CloudSightImageRequest.h

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ static const int kTPImageRequestTroubleError = 9011;
4141
@property (nonatomic, weak) id <CloudSightUploadProgressDelegate> uploadProgressDelegate;
4242
@property (nonatomic, retain) NSString *token;
4343
@property (nonatomic, retain) NSString *remoteUrl;
44+
@property (nonatomic, retain) NSString *language;
45+
@property (nonatomic, retain) NSString *locale;
4446
@property (nonatomic, retain) NSData *image;
4547
@property (nonatomic, assign) CGPoint location;
4648

CloudSight/CloudSightImageRequest.m

+18-11
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ - (id)initWithImage:(NSData *)image atLocation:(CGPoint)location withDelegate:(i
3838
self.image = image;
3939
self.location = location;
4040

41+
NSString *localeIdentifier = [[NSLocale currentLocale] localeIdentifier];
42+
NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:@"@.*"
43+
options:NSRegularExpressionCaseInsensitive
44+
error:nil];
45+
NSString *localeIdentifierWithoutCalendar = [regex stringByReplacingMatchesInString:localeIdentifier
46+
options:0
47+
range:NSMakeRange(0, [localeIdentifier length])
48+
withTemplate:@""];
49+
50+
self.locale = localeIdentifierWithoutCalendar;
51+
self.language = [[NSLocale preferredLanguages] objectAtIndex:0];
52+
4153
self.placemark = placemark;
4254
self.deviceId = deviceId;
4355

@@ -49,24 +61,19 @@ - (id)initWithImage:(NSData *)image atLocation:(CGPoint)location withDelegate:(i
4961

5062
- (NSDictionary *)buildRequestParameters
5163
{
52-
NSString *localeIdentifier = [[NSLocale currentLocale] localeIdentifier];
53-
NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:@"@.*"
54-
options:NSRegularExpressionCaseInsensitive
55-
error:nil];
56-
NSString *localeIdentifierWithoutCalendar = [regex stringByReplacingMatchesInString:localeIdentifier
57-
options:0
58-
range:NSMakeRange(0, [localeIdentifier length])
59-
withTemplate:@""];
6064

6165
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:@{
62-
@"image_request[locale]" : localeIdentifierWithoutCalendar,
63-
@"image_request[language]" : [[NSLocale preferredLanguages] objectAtIndex:0],
64-
@"image_request[device_id]" : self.deviceId,
66+
@"image_request[locale]" : self.locale,
67+
@"image_request[language]" : self.language,
6568
@"image_request[latitude]" : [NSNumber numberWithDouble:self.placemark.coordinate.latitude],
6669
@"image_request[longitude]" : [NSNumber numberWithDouble:self.placemark.coordinate.longitude],
6770
@"image_request[altitude]" : [NSNumber numberWithDouble:self.placemark.altitude]
6871
}];
6972

73+
if (self.deviceId != nil) {
74+
[params setValue:self.deviceId forKey:@"image_request[device_id]"];
75+
}
76+
7077
if (self.location.x != 0.000000 || self.location.y != 0.000000) {
7178
NSString *focusX = [[NSString alloc]initWithFormat:@"%f", self.location.x];
7279
[params setValue:focusX forKey:@"focus[x]"];

0 commit comments

Comments
 (0)