diff --git a/src/ios/ios.pyx b/src/ios/ios.pyx index 8f16c94..7ed3423 100644 --- a/src/ios/ios.pyx +++ b/src/ios/ios.pyx @@ -13,6 +13,7 @@ cdef extern from "ios_wrapper.h": ctypedef void (*ios_send_email_cb)(char *, void *) 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) cdef void _send_email_done(char *status, void *data): cdef object callback = data @@ -20,11 +21,43 @@ cdef void _send_email_done(char *status, void *data): Py_DECREF(callback) +# +# Support for webbrowser module +# + +class IosBrowser(object): + def open(self, url, new=0, autoraise=True): + open_url(url) + def open_new(self, url): + open_url(url) + def open_new_tab(self, url): + open_url(url) + +import webbrowser +webbrowser.register('ios', IosBrowser, None, -1) + # # API # -__version__ = (1, 0, 0) +__version__ = (1, 1, 0) + +def open_url(url): + '''Open an URL in Safari + + :Parameters: + `url`: str + The url string + ''' + cdef char *j_url = NULL + + if url is not None: + if type(url) is unicode: + url = url.encode('UTF-8') + j_url = url + + ios_open_url(j_url) + def send_email(subject, text, mimetype=None, filename=None, filename_alias=None, callback=None): '''Send an email using the IOS api. diff --git a/src/ios/ios_browser.m b/src/ios/ios_browser.m new file mode 100644 index 0000000..9bc4450 --- /dev/null +++ b/src/ios/ios_browser.m @@ -0,0 +1,13 @@ +/* + * Browser support + */ + +#import +#import +#include "ios_wrapper.h" + +void ios_open_url(char *url) +{ + NSString *nsurl = [NSString stringWithCString:(char *)url encoding:NSUTF8StringEncoding]; + [[UIApplication sharedApplication] openURL:[NSURL URLWithString: nsurl]]; +} diff --git a/src/ios/ios_wrapper.h b/src/ios/ios_wrapper.h index e3c34b5..fe2b0e6 100644 --- a/src/ios/ios_wrapper.h +++ b/src/ios/ios_wrapper.h @@ -1,6 +1,8 @@ #ifndef __IOS_WRAPPER #define __IOS_WRAPPER +void ios_open_url(char *url); + typedef void (*ios_send_email_cb)(char *, void *); int ios_send_email(char *subject, char *text, char *mimetype, char *filename, diff --git a/src/ios/setup.py b/src/ios/setup.py index f628e2b..0f9d282 100755 --- a/src/ios/setup.py +++ b/src/ios/setup.py @@ -5,7 +5,7 @@ setup(name='ios', version='1.0', ext_modules=[ Extension( - 'ios', ['ios.c', 'ios_mail.m'], + 'ios', ['ios.c', 'ios_mail.m', 'ios_browser.m'], libraries=[ ], library_dirs=[], )