Merge pull request #243 from shivan1b/add-webview

Add webview
This commit is contained in:
Akshay Arora 2017-05-14 09:59:36 +05:30 committed by GitHub
commit 9dc04610e8
3 changed files with 52 additions and 0 deletions

View file

@ -14,6 +14,7 @@ cdef extern from "ios_wrapper.h":
int ios_send_email(char *subject, char *text, char *mimetype, char
*filename, char *filename_alias, ios_send_email_cb cb, void *userdata)
void ios_open_url(char *url)
void load_url_webview(char *url)
float ios_uiscreen_get_scale()
int ios_uiscreen_get_dpi()
@ -22,6 +23,29 @@ cdef void _send_email_done(char *status, void *data):
callback(status)
Py_DECREF(callback)
#
#Support for iOS webview
#
class IOSWebView(object):
def open(self, url):
open_url_wbv(url)
def open_url_wbv(url):
'''
OPEN URL in webview
:Parameters:
`url`: str
URL string
Example for opening up a web page in UIWebview::
import ios
url = "http://www.google.com"
ios.IOSWebView().open(url)
'''
load_url_webview(url)
#
# Support for webbrowser module

View file

@ -11,3 +11,30 @@ void ios_open_url(char *url)
NSString *nsurl = [NSString stringWithCString:(char *)url encoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: nsurl]];
}
/*
* Webview support
*/
void load_url_webview(char *url)
{
NSString *nsurl = [NSString stringWithCString:(char *)url encoding:NSUTF8StringEncoding];
UIWebView *webView = [[UIWebView alloc] initWithFrame: CGRectMake(0, 0, 320, 480)];
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *view = [window.rootViewController view];
[view addSubview:webView];
NSURL *ur = [[NSURL alloc] initWithString: nsurl];
NSURLRequest *req = [[NSURLRequest alloc] initWithURL: ur];
[webView loadRequest: req];
[req release];
[ur release];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setTitle:@"X" forState:UIControlStateNormal];
button.frame = CGRectMake(0.0, 0.0, 40, 40);
[button addTarget:webView
action:@selector(removeFromSuperview) forControlEvents:UIControlEventTouchDown];
[webView addSubview:button];
[button release];
[webView release];
}

View file

@ -4,6 +4,7 @@
float ios_uiscreen_get_scale(void);
int ios_uiscreen_get_dpi(void);
void ios_open_url(char *url);
void load_url_webview(char *url);
typedef void (*ios_send_email_cb)(char *, void *);