forked from organicmaps/organicmaps
[ios] open social media links in installed applications from the PlacePage
Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
parent
11c174f254
commit
db0aeb4194
5 changed files with 21 additions and 20 deletions
|
@ -64,13 +64,14 @@ static inline CGFloat LengthCGPoint(CGPoint point)
|
|||
|
||||
@interface UIViewController (Safari)
|
||||
|
||||
// Opens http(s) urls in SFSafariViewController.
|
||||
// Does nothing and returns NO (false) if the url is invalid.
|
||||
/// Open URL internally in SFSafariViewController. Returns NO (false) if the url id invalid.
|
||||
- (BOOL)openUrl:(NSString *)urlString;
|
||||
|
||||
// Pass safari = YES (true) to open url externally, and NO (false) to open
|
||||
// in SFSafariViewController (see the method above).
|
||||
- (BOOL)openUrl:(NSString *)urlString inSafari:(BOOL)safari;
|
||||
/// Open URL externally in installed application (or in Safari if there are no appropriate application) if possible or internally in SFSafariViewController. Returns NO (false) if the url id invalid.
|
||||
///
|
||||
/// @param urlString: URL string to open.
|
||||
/// @param externally: If true, try to open URL in installed application or in Safari, otherwise open in internal browser without leaving the app.
|
||||
- (BOOL)openUrl:(NSString *)urlString externally:(BOOL)externally;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -171,10 +171,10 @@
|
|||
|
||||
- (BOOL)openUrl:(NSString * _Nonnull)urlString
|
||||
{
|
||||
return [self openUrl:urlString inSafari:NO];
|
||||
return [self openUrl:urlString externally:NO];
|
||||
}
|
||||
|
||||
- (BOOL)openUrl:(NSString *)urlString inSafari:(BOOL)safari
|
||||
- (BOOL)openUrl:(NSString *)urlString externally:(BOOL)externally
|
||||
{
|
||||
// TODO: This is a temporary workaround to open cyrillic/non-ASCII URLs.
|
||||
// URLs in OSM are stored in UTF-8. NSURL constructor documentation says:
|
||||
|
@ -205,7 +205,7 @@
|
|||
urlc.scheme = @"http";
|
||||
|
||||
NSURL * url = urlc.URL;
|
||||
if (safari)
|
||||
if (externally && [UIApplication.sharedApplication canOpenURL:url])
|
||||
{
|
||||
[UIApplication.sharedApplication openURL:url options:@{} completionHandler:nil];
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ extension BottomMenuInteractor: BottomMenuInteractorProtocol {
|
|||
if url == "https://organicmaps.app/donate/" {
|
||||
url = L("translated_om_site_url") + "donate/"
|
||||
}
|
||||
viewController?.openUrl(url, inSafari: true)
|
||||
viewController?.openUrl(url, externally: true)
|
||||
}
|
||||
|
||||
func downloadMaps() {
|
||||
|
|
|
@ -303,7 +303,7 @@ private extension AboutController {
|
|||
case .twitter: fallthrough
|
||||
case .instagram: fallthrough
|
||||
case .linkedin:
|
||||
self?.openUrl(socialMedia.link, inSafari: true)
|
||||
self?.openUrl(socialMedia.link, externally: true)
|
||||
case .organicMapsEmail:
|
||||
guard let link = socialMedia.link else { fatalError("The Organic Maps email link should be provided.") }
|
||||
self?.sendEmailWith(header: "Organic Maps", toRecipients: [link])
|
||||
|
|
|
@ -229,48 +229,48 @@ using namespace storage;
|
|||
}
|
||||
|
||||
- (void)openWebsite:(PlacePageData *)data {
|
||||
[self.ownerViewController openUrl:data.infoData.website];
|
||||
[self.ownerViewController openUrl:data.infoData.website externally:YES];
|
||||
}
|
||||
|
||||
- (void)openWebsiteMenu:(PlacePageData *)data {
|
||||
[self.ownerViewController openUrl:data.infoData.websiteMenu];
|
||||
[self.ownerViewController openUrl:data.infoData.websiteMenu externally:YES];
|
||||
}
|
||||
|
||||
- (void)openKayak:(PlacePageData *)data {
|
||||
[self.ownerViewController openUrl:data.infoData.kayak];
|
||||
[self.ownerViewController openUrl:data.infoData.kayak externally:YES];
|
||||
}
|
||||
|
||||
- (void)openWikipedia:(PlacePageData *)data {
|
||||
[self.ownerViewController openUrl:data.infoData.wikipedia];
|
||||
[self.ownerViewController openUrl:data.infoData.wikipedia externally:YES];
|
||||
}
|
||||
|
||||
- (void)openWikimediaCommons:(PlacePageData *)data {
|
||||
[self.ownerViewController openUrl:data.infoData.wikimediaCommons];
|
||||
[self.ownerViewController openUrl:data.infoData.wikimediaCommons externally:YES];
|
||||
}
|
||||
|
||||
- (void)openFacebook:(PlacePageData *)data {
|
||||
std::string const fullUrl = osm::socialContactToURL(osm::MapObject::MetadataID::FMD_CONTACT_FACEBOOK, [data.infoData.facebook UTF8String]);
|
||||
[self.ownerViewController openUrl:ToNSString(fullUrl)];
|
||||
[self.ownerViewController openUrl:ToNSString(fullUrl) externally:YES];
|
||||
}
|
||||
|
||||
- (void)openInstagram:(PlacePageData *)data {
|
||||
std::string const fullUrl = osm::socialContactToURL(osm::MapObject::MetadataID::FMD_CONTACT_INSTAGRAM, [data.infoData.instagram UTF8String]);
|
||||
[self.ownerViewController openUrl:ToNSString(fullUrl)];
|
||||
[self.ownerViewController openUrl:ToNSString(fullUrl) externally:YES];
|
||||
}
|
||||
|
||||
- (void)openTwitter:(PlacePageData *)data {
|
||||
std::string const fullUrl = osm::socialContactToURL(osm::MapObject::MetadataID::FMD_CONTACT_TWITTER, [data.infoData.twitter UTF8String]);
|
||||
[self.ownerViewController openUrl:ToNSString(fullUrl)];
|
||||
[self.ownerViewController openUrl:ToNSString(fullUrl) externally:YES];
|
||||
}
|
||||
|
||||
- (void)openVk:(PlacePageData *)data {
|
||||
std::string const fullUrl = osm::socialContactToURL(osm::MapObject::MetadataID::FMD_CONTACT_VK, [data.infoData.vk UTF8String]);
|
||||
[self.ownerViewController openUrl:ToNSString(fullUrl)];
|
||||
[self.ownerViewController openUrl:ToNSString(fullUrl) externally:YES];
|
||||
}
|
||||
|
||||
- (void)openLine:(PlacePageData *)data {
|
||||
std::string const fullUrl = osm::socialContactToURL(osm::MapObject::MetadataID::FMD_CONTACT_LINE, [data.infoData.line UTF8String]);
|
||||
[self.ownerViewController openUrl:ToNSString(fullUrl)];
|
||||
[self.ownerViewController openUrl:ToNSString(fullUrl) externally:YES];
|
||||
}
|
||||
|
||||
- (void)openEmail:(PlacePageData *)data {
|
||||
|
|
Loading…
Add table
Reference in a new issue