IOS APNS not received in background

I am trying to get a notification in the background. I do not want the user to run my application to receive a warning in the notification. But it looks like iOS is not sending a notification to the didReceiveRemoteNotification callback function: Any inputs?

Is there anything special I need to do in order to get clicked in the background.

FYI: I also tried using the voip mode and nothing else !!!

Basically, I want my application to receive a notification without launching my application and to perform some actions while the application is running in the background.

+1
source share
2 answers

But it looks like iOS is not sending a notification to the didReceiveRemoteNotification callback function:

It's true. If your application is in the background, you will not receive a notification of an incoming push notification, unless the user starts the application by interacting with the notification.

Basically, I want my application to be notified without having to launch my application / user intervention and perform some actions while running in the background.

It's impossible.

+5
source

You can get deleted notifications and wake up. But it’s important to understand the current implementation and how this affects the behavior of the application. All items are subject to change under Apple. At the time of this writing, you need to know (the first 2 people are obviously grok):

  • First of all, your application should include “Remote Notifications” as the required background mode.
  • Your application must register for remote notifications, as described in https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html
  • You MUST know about which callback in your application (UIApplicationDelegate for Swift) is based on your current state of the application (foreground, background, paused, etc.).
    • Foreground - will call application:didReceiveRemoteNotification or more preferably application:didReceiveRemoteNotification:fetchCompletionHandler
    • Background / Suspended - will ONLY (potentially) call application:didReceiveRemoteNotification:fetchCompletionHandler , and you better call that fetchCompletionHandler for 30 seconds or your application terminates. If you have not implemented the method using fetchCompletionHandler, then you can probably only get the icon / alert from System IF , which you put in the contents of the APN message. Otherwise, you will not see anything.

Now here's the catch. The current iOS profiles of your application, and THEN decides whether to really wake your application. If you spend a lot of time testing APN, this will ultimately lead to your application becoming a bad citizen and it will not awaken your application (unless you are connected to power, at least). It will just wait for your application to start (which you can encourage the user to do through the system icon / notification in your APN message) and then put this remote notification in makeOutions for make / willFinishLaunchingWithOptions under the key UIApplicationLaunchOptionsRemoteNotificationKey

+1
source

Source: https://habr.com/ru/post/1260981/


All Articles