[ios] Added back geo URI Scheme support

This commit is contained in:
Alex Zolotarev 2012-11-08 04:35:33 +03:00 committed by Alex Zolotarev
parent 9c4d6350e9
commit b5965f5995
7 changed files with 60 additions and 29 deletions

View file

@ -38,8 +38,6 @@
- (IBAction)OnSearchClicked:(id)sender;
- (IBAction)OnBookmarksClicked:(id)sender;
-(BOOL) OnProcessURL:(NSString*)url;
- (void)showSearchResultAsBookmarkAtMercatorPoint:(m2::PointD const &)pt withInfo:(Framework::AddressInfo const &)info;
@property (nonatomic, retain) IBOutlet UIButton * m_myPositionButton;

View file

@ -603,10 +603,4 @@ NSInteger compareAddress(id l, id r, void * context)
GetFramework().SetupMeasurementSystem();
}
-(BOOL) OnProcessURL:(NSString*)url
{
GetFramework().SetViewportByURL([url UTF8String]);
return TRUE;
}
@end

View file

@ -9,6 +9,7 @@
#include "Framework.h"
#include "../../../platform/settings.hpp"
@implementation MapsAppDelegate
@synthesize m_mapViewController;
@ -112,14 +113,24 @@
return [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey] != nil;
}
// handleOpenURL is deprecaed now.
// http://stackoverflow.com/questions/3612460/lauching-app-with-url-via-uiapplicationdelegates-handleopenurl-working-under
/*
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
// We don't support HandleOpenUrl as it's deprecated from iOS 4.2
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
NSString * text = [[url absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
return [m_mapViewController OnProcessURL:text];
NSString * scheme = url.scheme;
NSLog(@"Launched with URL Scheme %@ from the app %@", url.scheme, sourceApplication);
// geo scheme support, see http://tools.ietf.org/html/rfc5870
if ([scheme isEqualToString:@"geo"])
{
GetFramework().SetViewportByURL([[url.absoluteString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding] UTF8String]);
return YES;
}
NSLog(@"Scheme %@ is not supported", scheme);
return NO;
}
*/
@end

View file

@ -31,6 +31,19 @@
<string>${CURRENT_PROJECT_VERSION}</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string>com.mapswithme.maps</string>
<key>CFBundleURLSchemes</key>
<array>
<string>geo</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>${CURRENT_PROJECT_VERSION}</string>
<key>LSRequiresIPhoneOS</key>

View file

@ -31,6 +31,19 @@
<string>${CURRENT_PROJECT_VERSION}</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>CFBundleURLName</key>
<string>com.mapswithme.maps</string>
<key>CFBundleURLSchemes</key>
<array>
<string>geo</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>${CURRENT_PROJECT_VERSION}</string>
<key>LSRequiresIPhoneOS</key>

View file

@ -25,7 +25,7 @@ namespace url_scheme
}
class DoParse
class DoGeoParse
{
Info & m_info;
@ -54,7 +54,7 @@ namespace url_scheme
}
public:
DoParse(Info & info) : m_info(info), m_mode(START)
DoGeoParse(Info & info) : m_info(info), m_mode(START)
{
}
@ -63,8 +63,11 @@ namespace url_scheme
switch (m_mode)
{
case START:
ASSERT(token == "geo" || token == "mapswithme", (token));
m_mode = LAT;
// Only geo scheme is supported by this parser
if (token != "geo")
m_mode = FINISH;
else
m_mode = LAT;
break;
case LAT:
@ -99,6 +102,6 @@ namespace url_scheme
void ParseURL(string const & s, Info & info)
{
strings::Tokenize(s, ":/?&=,", DoParse(info));
strings::Tokenize(s, ":/?&=,", DoGeoParse(info));
}
}

View file

@ -7,25 +7,24 @@ using namespace url_scheme;
UNIT_TEST(ProcessURL_Smoke)
{
Info info;
ParseURL("geo:53.666,27.666", info);
ParseGeoURL("geo:53.666,27.666", info);
TEST(info.IsValid(), ());
TEST_ALMOST_EQUAL(info.m_lat, 53.666, ());
TEST_ALMOST_EQUAL(info.m_lon, 27.666, ());
info.Reset();
ParseURL("mapswithme:53.666,27.666", info);
TEST(info.IsValid(), ());
TEST_ALMOST_EQUAL(info.m_lat, 53.666, ());
TEST_ALMOST_EQUAL(info.m_lon, 27.666, ());
info.Reset();
ParseURL("mapswithme://point/?lon=27.666&lat=53.666&zoom=10", info);
ParseGeoURL("geo://point/?lon=27.666&lat=53.666&zoom=10", info);
TEST(info.IsValid(), ());
TEST_ALMOST_EQUAL(info.m_lat, 53.666, ());
TEST_ALMOST_EQUAL(info.m_lon, 27.666, ());
TEST_ALMOST_EQUAL(info.m_zoom, 10.0, ());
info.Reset();
ParseURL("geo:53.666", info);
ParseGeoURL("geo:53.666", info);
TEST(!info.IsValid(), ());
info.Reset();
ParseGeoURL("mapswithme:123.33,32.22/showmethemagic", info);
TEST(!info.IsValid(), ());
}