ios: if no mail is configured, prevent crashing and return a status code "cannotsend".

This commit is contained in:
Mathieu Virbel 2012-05-25 18:39:48 +02:00
parent 7f5a10a6bf
commit e6e3879a9b
2 changed files with 13 additions and 5 deletions

View file

@ -77,7 +77,7 @@ def send_email(subject, text, mimetype=None, filename=None, filename_alias=None,
`callback`: func(status) `callback`: func(status)
Callback that can be called when the email interface have been Callback that can be called when the email interface have been
removed. A status will be passed as the first argument: "cancelled", removed. A status will be passed as the first argument: "cancelled",
"saved", "sent", "failed", "unknown". "saved", "sent", "failed", "unknown", "cannotsend".
.. note:: .. note::
@ -149,9 +149,13 @@ def send_email(subject, text, mimetype=None, filename=None, filename_alias=None,
Py_INCREF(callback) Py_INCREF(callback)
if ios_send_email(j_subject, j_text, j_mimetype, j_filename, ret = ios_send_email(j_subject, j_text, j_mimetype, j_filename,
j_filename_alias, _send_email_done, <void *>callback) == 0: j_filename_alias, _send_email_done, <void *>callback)
if ret == 0:
callback('failed') callback('failed')
return 0 return 0
elif ret == -1:
callback('cannotsend')
return 0
return 1 return 1

View file

@ -67,13 +67,17 @@ UIViewController *get_viewcontroller(void) {
int ios_send_email(char *subject, char *text, char *mimetype, char *filename, int ios_send_email(char *subject, char *text, char *mimetype, char *filename,
char *filename_alias, ios_send_email_cb callback, void *userdata) char *filename_alias, ios_send_email_cb callback, void *userdata)
{ {
UIViewController* viewController = get_viewcontroller(); UIViewController* viewController = get_viewcontroller();
if ( viewController == NULL ) { if ( viewController == NULL ) {
printf("ios_send_email: unable to get view controller"); printf("ios_send_email: unable to get view controller.\n");
return 0; return 0;
} }
if (! [MFMailComposeViewController canSendMail]) {
printf("ios_send_email: no available mail provider configured.\n");
return -1;
}
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init]; MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
InAppEmailViewController *inAppVc = [[InAppEmailViewController alloc] init]; InAppEmailViewController *inAppVc = [[InAppEmailViewController alloc] init];
inAppVc.callback = callback; inAppVc.callback = callback;