Perform background tasks when app is terminated

前端 未结 3 667
盖世英雄少女心
盖世英雄少女心 2020-11-29 08:36

I\'m creating an application for my school which should check every n minutes if there is a new mark on the website. To do this when the user login for the first time, the n

3条回答
  •  星月不相逢
    2020-11-29 09:15

    It's not possible to perform tasks like described in your question after the app is terminated. As described in the documentation:

    App Termination

    Apps must be prepared for termination to happen at any time and should not wait to save user data or perform other critical tasks. System-initiated termination is a normal part of an app’s life cycle. The system usually terminates apps so that it can reclaim memory and make room for other apps being launched by the user, but the system may also terminate apps that are misbehaving or not responding to events in a timely manner.

    Suspended apps receive no notification when they are terminated; the system kills the process and reclaims the corresponding memory. If an app is currently running in the background and not suspended, the system calls the applicationWillTerminate: of its app delegate prior to termination. The system does not call this method when the device reboots.

    In addition to the system terminating your app, the user can terminate your app explicitly using the multitasking UI. User-initiated termination has the same effect as terminating a suspended app. The app’s process is killed and no notification is sent to the app.

    Link: https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/TheAppLifeCycle/TheAppLifeCycle.html

    Edit:

    You cannot perform any task after the application is terminated. What you can do is get that calculation done from server side and send a Push Notification to the device.

提交回复
热议问题