Add System.openFile / System.openURL
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user