code updated

This commit is contained in:
Vladimir Enchev
2015-09-09 11:06:26 +03:00
parent cd313eb6d2
commit cb29e57168
3 changed files with 23 additions and 8 deletions

View File

@@ -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;
}

2
utils/utils.d.ts vendored
View File

@@ -178,5 +178,5 @@
* Opens url.
* @param url The url.
*/
export function openUrl(url: string): void
export function openUrl(url: string): boolean
}

View File

@@ -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;
}