-->

iOS: How can I send an email automatically with an

2019-08-19 09:11发布

问题:

I have a way to send email that works perfectly, but I would like to send it automatically, even if the iPad is in sleep mode.

The way to send email is here: How can I send an email with attachement using the API MailJet in iOS programmatically?

Thanks in advance.

回答1:

Background tasks like this are not easy to accomplish in iOS, Apple places obstacles in our way to prevent us doing so.

As Apple don't want us doing this, you should ask yourself why you need to do it. Do you intend to publish these works and have others utilise this feature or is it for use by you only?

There are many ways to fudge background tasks like these and whilst they work, they are considered 'hacks' and Apple may well reject your submission for utilising them, or worse, pull your app suddenly once it already has an established userbase.

I would reconsider what you are proposing, but if you still want to go ahead, my approach would be the following:

Create a webservivce that the app posts too with its APNS push token. This webservice then sends a silent push to the device every 6 hours, waking it from the background and allowing it to perform its task.

Note however, this involves having another component, the webserver. Furthermore, this is not condoned by Apple or myself, but it is an approach nonetheless.