diff --git a/api/iOS/api/MapsWithMeAPI.h b/api/iOS/api/MapsWithMeAPI.h index f11b3a07f6..89798c9d08 100644 --- a/api/iOS/api/MapsWithMeAPI.h +++ b/api/iOS/api/MapsWithMeAPI.h @@ -38,11 +38,11 @@ @property (nonatomic, assign) double lat; @property (nonatomic, assign) double lon; // [optional] pin title -@property (nonatomic, retain) NSString * optionalTitle; +@property (nonatomic, retain) NSString * title; // [optional] passed back to the app when pin is clicked, OR, if it's a valid url, // it will be opened from MapsWithMe after selecting "More Details..." for the pin -@property (nonatomic, retain) NSString * optionalId; -- (id) initWithLat:(double)lat lon:(double)lon title:(NSString *)title id:(NSString *)pinId; +@property (nonatomic, retain) NSString * idOrUrl; +- (id) initWithLat:(double)lat lon:(double)lon title:(NSString *)title and:(NSString *)idOrUrl; @end @@ -51,7 +51,7 @@ // returns YES if url is received from MapsWithMe and can be parsed + (BOOL) isMapsWithMeUrl:(NSURL *)url; -// returns nil if received url is invalid or not from MapsWithMe +// returns nil if user didn't select any pin and simply pressed "Back" button + (MWMPin *) pinFromUrl:(NSURL *)url; // returns NO if MapsWithMe is not installed or outdated version doesn't support API calls + (BOOL) isApiSupported; @@ -59,7 +59,7 @@ + (BOOL) showMap; // Displays given point on a map, title and id are optional // If id contains valid url, it will be opened from MapsWithMe after selecting "More Details..." for the pin -+ (BOOL) showLat:(double)lat lon:(double)lon title:(NSString *)optionalTitle id:(NSString *)optionalId; ++ (BOOL) showLat:(double)lat lon:(double)lon title:(NSString *)title and:(NSString *)idOrUrl; // The same as above but using pin wrapper + (BOOL) showPin:(MWMPin *)pin; // Displays any number of pins diff --git a/api/iOS/api/MapsWithMeAPI.m b/api/iOS/api/MapsWithMeAPI.m index 5bbe4e6b2f..dc9e33f19b 100644 --- a/api/iOS/api/MapsWithMeAPI.m +++ b/api/iOS/api/MapsWithMeAPI.m @@ -44,22 +44,22 @@ static NSString * MWMUrlScheme = @"mapswithme://"; return self; } -- (id) initWithLat:(double)lat lon:(double)lon title:(NSString *)title id:(NSString *)pinId +- (id) initWithLat:(double)lat lon:(double)lon title:(NSString *)title and:(NSString *)idOrUrl { if ((self = [super init])) { self.lat = lat; self.lon = lon; - self.optionalTitle = title; - self.optionalId = pinId; + self.title = title; + self.idOrUrl = idOrUrl; } return self; } - (void)dealloc { - self.optionalTitle = nil; - self.optionalId = nil; + self.title = nil; + self.idOrUrl = nil; [super dealloc]; } @end @@ -108,9 +108,9 @@ static NSString * MWMUrlScheme = @"mapswithme://"; } } else if ([key isEqualToString:@"n"]) - pin.optionalTitle = [[values objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + pin.title = [[values objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; else if ([key isEqualToString:@"id"]) - pin.optionalId = [[values objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + pin.idOrUrl = [[values objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; else NSLog(@"Unsupported url parameters: %@", values); } @@ -132,9 +132,9 @@ static NSString * MWMUrlScheme = @"mapswithme://"; return [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[MWMUrlScheme stringByAppendingFormat:@"map?v=%d", MAPSWITHME_API_VERSION]]]; } -+ (BOOL) showLat:(double)lat lon:(double)lon title:(NSString *)optionalTitle id:(NSString *)optionalId ++ (BOOL) showLat:(double)lat lon:(double)lon title:(NSString *)title and:(NSString *)idOrUrl { - MWMPin * pin = [[[MWMPin alloc] initWithLat:lat lon:lon title:optionalTitle id:optionalId] autorelease]; + MWMPin * pin = [[[MWMPin alloc] initWithLat:lat lon:lon title:title and:idOrUrl] autorelease]; return [MWMApi showPin:pin]; } @@ -166,10 +166,10 @@ static NSString * MWMUrlScheme = @"mapswithme://"; [str appendFormat:@"ll=%f,%f&", point.lat, point.lon]; @autoreleasepool { - if (point.optionalTitle) - [str appendFormat:@"n=%@&", [point.optionalTitle stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; - if (point.optionalId) - [str appendFormat:@"id=%@&", [point.optionalId stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; + if (point.title) + [str appendFormat:@"n=%@&", [point.title stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; + if (point.idOrUrl) + [str appendFormat:@"id=%@&", [point.idOrUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; } } @@ -229,7 +229,7 @@ static NSString * mapsWithMeIsNotInstalledPage = { UIWebView * webView = [[[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease]; // check that we have Internet connection and display fresh online page if possible - if (gethostbyname("google.com")) + if (gethostbyname("mapswith.me")) [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://mapswith.me/api_mwm_not_installed"]]]; else [webView loadHTMLString:mapsWithMeIsNotInstalledPage baseURL:[NSURL URLWithString:@"http://mapswith.me/"]]; diff --git a/api/iOS/capitals-example/Capitals/AppDelegate.m b/api/iOS/capitals-example/Capitals/AppDelegate.m index 5216b057df..ea59875de3 100644 --- a/api/iOS/capitals-example/Capitals/AppDelegate.m +++ b/api/iOS/capitals-example/Capitals/AppDelegate.m @@ -43,7 +43,7 @@ MWMPin * pin = [MWMApi pinFromUrl:url]; if (pin) { - size_t const cityId = [pin.optionalId integerValue]; + size_t const cityId = [pin.idOrUrl integerValue]; // display selected page based on passed id if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { diff --git a/api/iOS/capitals-example/Capitals/CityDetailViewController.m b/api/iOS/capitals-example/Capitals/CityDetailViewController.m index 3a5e86ed40..48086c06f8 100644 --- a/api/iOS/capitals-example/Capitals/CityDetailViewController.m +++ b/api/iOS/capitals-example/Capitals/CityDetailViewController.m @@ -52,7 +52,7 @@ pinId = [NSString stringWithFormat:@"http://en.wikipedia.org/wiki/%@", [self urlEncode:city->name]]; else pinId = [NSString stringWithFormat:@"%ld", _cityIndex]; - [MWMApi showLat:city->lat lon:city->lon title:city->name id:pinId]; + [MWMApi showLat:city->lat lon:city->lon title:city->name and:pinId]; } - (void)dealloc diff --git a/api/iOS/capitals-example/Capitals/MasterViewController.m b/api/iOS/capitals-example/Capitals/MasterViewController.m index 20d33d59bd..8f5c59523a 100644 --- a/api/iOS/capitals-example/Capitals/MasterViewController.m +++ b/api/iOS/capitals-example/Capitals/MasterViewController.m @@ -44,7 +44,7 @@ { NSString * pinId = [[[NSString alloc] initWithFormat:@"%ld", i] autorelease]; // Note that url is empty - it means "More details" button for a pin in MapsWithMe will lead back to this example app - MWMPin * pin = [[[MWMPin alloc] initWithLat:CAPITALS[i].lat lon:CAPITALS[i].lon title:CAPITALS[i].name id:pinId] autorelease]; + MWMPin * pin = [[[MWMPin alloc] initWithLat:CAPITALS[i].lat lon:CAPITALS[i].lon title:CAPITALS[i].name and:pinId] autorelease]; [array addObject:pin]; }