Interested in how to implement local notifications when an application is in the background, that is, each notification has such a method (first there is a connection to the API , which changes once a minute and then filling):

  let content = UNMutableNotificationContent() content.title = name let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats:true) UIApplication.shared.applicationIconBadgeNumber = 0 let reguest = UNNotificationRequest(identifier: "identifier", content: content, trigger: trigger) UNUserNotificationCenter.current().add(reguest) { (error) in} 

which works once a minute when the application is on the screen, but as soon as it collapses, that's all. How to create a method in the background at intervals, say, once a minute?

  • Specify, please, it is about Notifications for the user or Fetch in the background? - Vitaly
  • Well, I have never made such notifications so far, so I can be wrong in the concept of their creation. As far as I understand in the background, the application should throw a request to the server and compare the data with its own, if they are different then a notification should pop up. Fetch in the background and notifications are not things related to each other?) Sorry for stupid questions - Romik romikromik
  • one
    Transfer the logic to the server and use regular notifications. - Ivan Kramarchuk
  • You shuffle every minute a recurring notification that will bomb every minute. Bundle of recurring notifications growing like a snowball. Are you sure that this is exactly the result you need? - kelin 5:26 pm

2 answers 2

The code you give is able to work in the background. Rather, the problem is that your application as a whole does not work in this mode. How to make it work? - read the documentation .

In iOS, you can do a limited number of tasks in the backup:

  1. Briefly execute the code after closing the apa (like up to 3 minutes)
  2. Download / upload file.
  3. Play / record audio.
  4. Track geolocation.
  5. VoIP.
  6. Regular content download, such as news ups. (iOS itself decides when you can download).
  7. Bluetooth and other external devices.

Moreover, each item has strict limitations. You will not be able to download weather data under the guise of playing music (and it was possible before).

    I read the question several times, did not understand what problem you are trying, you want to solve, plus looked at your questions. Perhaps your task will suit Background Update Notification, in this documentation description The only thing that they should not be sent too often Or read about work in the ios background