From cd313eb6d2cfeb834f4baf13488ef8ac7fc8154b Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Wed, 9 Sep 2015 10:34:21 +0300 Subject: [PATCH 1/2] openUrl added --- utils/utils.android.ts | 7 +++++++ utils/utils.d.ts | 6 ++++++ utils/utils.ios.ts | 11 +++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/utils/utils.android.ts b/utils/utils.android.ts index 4cd78710b..22e5d63b5 100644 --- a/utils/utils.android.ts +++ b/utils/utils.android.ts @@ -130,4 +130,11 @@ export module ad { export function GC() { gc(); +} + +export function openUrl(url: string): void { + var context = ad.getApplicationContext(); + if (context) { + context.startActivity(new android.content.Intent(android.content.Intent.ACTION_VIEW, android.net.Uri.parse(url))); + } } \ No newline at end of file diff --git a/utils/utils.d.ts b/utils/utils.d.ts index e6b560f42..7c168ee72 100644 --- a/utils/utils.d.ts +++ b/utils/utils.d.ts @@ -173,4 +173,10 @@ * @param source The JSON or JSONP string. */ export function parseJSON(source: string): any + + /** + * Opens url. + * @param url The url. + */ + export function openUrl(url: string): void } diff --git a/utils/utils.ios.ts b/utils/utils.ios.ts index e479ffa07..46485044e 100644 --- a/utils/utils.ios.ts +++ b/utils/utils.ios.ts @@ -50,7 +50,7 @@ export module ios { var greenRef = new interop.Reference(); var blueRef = new interop.Reference(); var alphaRef = new interop.Reference(); - + uiColor.getRedGreenBlueAlpha(redRef, greenRef, blueRef, alphaRef); var red = redRef.value * 255; var green = greenRef.value * 255; @@ -142,8 +142,15 @@ export module ios { rootView.measure(widthSpec, heightSpec); rootView.layout(left, top, width, height); } -} +} export function GC() { __collect(); +} + +export function openUrl(url: string): void { + var sharedApp = UIApplication.sharedApplication() + if (sharedApp) { + sharedApp.openURL(NSURL.URLWithString(url)); + } } \ No newline at end of file From cb29e57168fc7303a9cdc2a35754ee1913bdf595 Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Wed, 9 Sep 2015 11:06:26 +0300 Subject: [PATCH 2/2] code updated --- utils/utils.android.ts | 14 +++++++++++--- utils/utils.d.ts | 2 +- utils/utils.ios.ts | 15 +++++++++++---- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/utils/utils.android.ts b/utils/utils.android.ts index 22e5d63b5..bb79d4406 100644 --- a/utils/utils.android.ts +++ b/utils/utils.android.ts @@ -132,9 +132,17 @@ export function GC() { gc(); } -export function openUrl(url: string): void { +export function openUrl(location: string): boolean { var context = ad.getApplicationContext(); - if (context) { - context.startActivity(new android.content.Intent(android.content.Intent.ACTION_VIEW, android.net.Uri.parse(url))); + try { + var intent = new android.content.Intent(android.content.Intent.ACTION_VIEW, android.net.Uri.parse(location.trim())); + intent.addFlags(android.content.Intent.FLAG_ACTIVITY_NEW_TASK); + + context.startActivity(intent); + } catch (e) { + // We Don't do anything with an error. We just output it + console.error("Error in OpenURL", e); + return false; } + return true; } \ No newline at end of file diff --git a/utils/utils.d.ts b/utils/utils.d.ts index 7c168ee72..b044b2b20 100644 --- a/utils/utils.d.ts +++ b/utils/utils.d.ts @@ -178,5 +178,5 @@ * Opens url. * @param url The url. */ - export function openUrl(url: string): void + export function openUrl(url: string): boolean } diff --git a/utils/utils.ios.ts b/utils/utils.ios.ts index 46485044e..b96b9de01 100644 --- a/utils/utils.ios.ts +++ b/utils/utils.ios.ts @@ -148,9 +148,16 @@ export function GC() { __collect(); } -export function openUrl(url: string): void { - var sharedApp = UIApplication.sharedApplication() - if (sharedApp) { - sharedApp.openURL(NSURL.URLWithString(url)); +export function openUrl(location: string): boolean { + try { + var url = NSURL.URLWithString(location.trim()); + if (UIApplication.sharedApplication().canOpenURL(url)) { + return UIApplication.sharedApplication().openURL(url); + } } + catch (e) { + // We Don't do anything with an error. We just output it + console.error("Error in OpenURL", e); + } + return false; } \ No newline at end of file