Add System.openFile / System.openURL

This commit is contained in:
Joshua Granick
2016-11-11 16:46:43 -08:00
parent c850459fa5
commit 54a8f32f60
5 changed files with 196 additions and 0 deletions

View File

@@ -1328,6 +1328,24 @@ namespace lime {
}
void lime_system_open_file (HxString path) {
#ifdef IPHONE
System::OpenFile (path.__s);
#endif
}
void lime_system_open_url (HxString url, HxString target) {
#ifdef IPHONE
System::OpenURL (url.__s, target.__s);
#endif
}
bool lime_system_set_allow_screen_timeout (bool allow) {
return System::SetAllowScreenTimeout (allow);
@@ -1734,6 +1752,8 @@ namespace lime {
DEFINE_PRIME1 (lime_system_get_display);
DEFINE_PRIME0 (lime_system_get_num_displays);
DEFINE_PRIME0 (lime_system_get_timer);
DEFINE_PRIME1v (lime_system_open_file);
DEFINE_PRIME2v (lime_system_open_url);
DEFINE_PRIME1 (lime_system_set_allow_screen_timeout);
DEFINE_PRIME2v (lime_text_event_manager_register);
DEFINE_PRIME3 (lime_text_layout_create);

View File

@@ -54,4 +54,48 @@ namespace lime {
}
void System::OpenFile (const char* path) {
OpenURL (path, NULL);
}
void System::OpenURL (const char* url, const char* target) {
#ifndef OBJC_ARC
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
#endif
UIApplication *application = [UIApplication sharedApplication];
NSString *str = [[NSString alloc] initWithUTF8String: url];
NSURL *_url = [NSURL URLWithString: str];
if ([[UIApplication sharedApplication] canOpenURL: _url]) {
if ([application respondsToSelector: @selector (openURL:options:completionHandler:)]) {
[application openURL: _url options: @{}
completionHandler:^(BOOL success) {
//NSLog(@"Open %@: %d", _url, success);
}
];
} else {
BOOL success = [application openURL: _url];
//NSLog(@"Open %@: %d",scheme,success);
}
}
#ifndef OBJC_ARC
[str release];
[pool drain];
#endif
}
}