What are the options, when local notification is triggered while the application is in the background, catch it and call the desired method. Without user intervention (clicking on the alert itself). For example, a notification is triggered at one in the morning every day, and at this moment a function is called that pulls the weather data from the server. Does the User Notification framework allow you to do this? Or are there any other options?
- As far as I know, there is no such possibility. iOS is ready to occasionally call the update functions of your application, but it does not guarantee the exact frequency and time of these calls (this remains at its discretion). In addition, iOS does not allow any background programs to work except music and gadgets for a long time. - Ivan Kramarchuk
2 answers
Background Update Notification is suitable for your task, they are similar to “normal” notifications, except when there is no alert, they are also called silent notifications, they also contain the content-available = 1 flag, which means what is payload, for example, it can be a link to a remote resource to which you need to access, you can get access to the payload in the didReceiveRemoteNotification method. The main salt of these notifications is that when the application was in the background and the system “put it to sleep”, the system awakens the application and you get some time limit as well as payload to the didReceiveRemoteNotification method. Apple ask to send notifications no more than 2-3 pieces per hour, this will be enough for you
For this, it is not necessary to pervert so. For actual weather data, you can start them asynchronously load them into
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. return YES; } and store them in what thread singletone. And yes, you have an application in the background lives no more than 10 minutes