Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background task in iOS action extension

I'm working on an action extension for an app which prepares some data for the user and then uses MailCore2 to send this information to a SMTP server. Preparing data is done very fast, but sending the email might take some time (depending on its size). That's why I'm looking for a way to handle the sending activities in the background. But this results in some problems with different solutions:

  1. Using URLSession. This is the first way to go for handling big uploads or downloads in an iOS extension. But the problem is that MailCore2 does not use URLSessions to transmit the data to the mail server. So this is not usable. Or is it possible to somehow 'wrap' this call in an URLSession?

  2. Using UNUserNotificationCenter and send a local notification from the extension after data preparation. The idea is to start the sending task in the main app after receiving this notification. Problem: the notifications userNotificationCenter didReceive method is only called, when the user clicks the notification. A simple badge notification does not call the delegate method.

  3. Using Background Fetch. This is working fine in the simulator, but on an iOS device there is an error when connecting to the SMTP server. I came across the same HELO problem as described in github.com/MailCore/mailcore2/issues/252. For this issue, a solution should be MCOSMTPSession.isUseHeloIPEnabled = true, but this might not work for all servers. So also not a perfect solution.

Any ideas, how to handle such a task? Or how to deal with one of the solutions mentioned above?

Edit: as this question does not receive any answers yet: what is unclear or which additional information is required?

like image 645
mixable Avatar asked Jun 05 '18 06:06

mixable


2 Answers

It seems like you can't schedule long running running tasks in background from an extension.Refer here(Some APIs Are Unavailable to App Extensions)

Among the solutions you suggested,my suggestion would be to try using silent push notifications ,you can call an api at the preparing data stage,then sent a silent push from server and perform the background task when the silent push arrives.

like image 167
Tibin Thomas Avatar answered Oct 22 '22 12:10

Tibin Thomas


Judging from your response, your difficulties is that you need to allow background activities. You can do that by following a tutorial such as this one.

like image 44
Francois Nadeau Avatar answered Oct 22 '22 12:10

Francois Nadeau