ios: if no mail is configured, prevent crashing and return a status code "cannotsend".
This commit is contained in:
parent
7f5a10a6bf
commit
e6e3879a9b
2 changed files with 13 additions and 5 deletions
|
@ -77,7 +77,7 @@ def send_email(subject, text, mimetype=None, filename=None, filename_alias=None,
|
|||
`callback`: func(status)
|
||||
Callback that can be called when the email interface have been
|
||||
removed. A status will be passed as the first argument: "cancelled",
|
||||
"saved", "sent", "failed", "unknown".
|
||||
"saved", "sent", "failed", "unknown", "cannotsend".
|
||||
|
||||
.. note::
|
||||
|
||||
|
@ -149,9 +149,13 @@ def send_email(subject, text, mimetype=None, filename=None, filename_alias=None,
|
|||
|
||||
Py_INCREF(callback)
|
||||
|
||||
if ios_send_email(j_subject, j_text, j_mimetype, j_filename,
|
||||
j_filename_alias, _send_email_done, <void *>callback) == 0:
|
||||
ret = ios_send_email(j_subject, j_text, j_mimetype, j_filename,
|
||||
j_filename_alias, _send_email_done, <void *>callback)
|
||||
if ret == 0:
|
||||
callback('failed')
|
||||
return 0
|
||||
elif ret == -1:
|
||||
callback('cannotsend')
|
||||
return 0
|
||||
|
||||
return 1
|
||||
|
|
|
@ -67,13 +67,17 @@ UIViewController *get_viewcontroller(void) {
|
|||
int ios_send_email(char *subject, char *text, char *mimetype, char *filename,
|
||||
char *filename_alias, ios_send_email_cb callback, void *userdata)
|
||||
{
|
||||
|
||||
UIViewController* viewController = get_viewcontroller();
|
||||
if ( viewController == NULL ) {
|
||||
printf("ios_send_email: unable to get view controller");
|
||||
printf("ios_send_email: unable to get view controller.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (! [MFMailComposeViewController canSendMail]) {
|
||||
printf("ios_send_email: no available mail provider configured.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
|
||||
InAppEmailViewController *inAppVc = [[InAppEmailViewController alloc] init];
|
||||
inAppVc.callback = callback;
|
||||
|
|
Loading…
Reference in a new issue