I was hoping that the iOS11 release will fix the silent push issue, which was in the latest betas and GM version of iOS.
Currently I'm struggling to understand, why I don't receive any silent push messages, which should actually wake up my app to perform some needed tasks in the background.
In iOS 10 I just use the background fetch capability and implemented the 'wake-up-code' in my AppDelegate like the code below.
In iOS 11 the registering code is still working fine and my backend is also delivering the push notification to Apples DEV servers (sandbox) and also to the PROD servers (production release). Unfortunately the function func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
is never called by the silent push notifications.
Did I actually miss something here for iOS 11?
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
// .. some variables here ...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// register silent push notification in backend
application.registerForRemoteNotifications()
// ... some code here ...
// Set Background Fetch Intervall for background services / terminated app
UIApplication.shared.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)
// ... some code here ...
return true
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let tokenParts = deviceToken.map { data -> String in
return String(format: "%02.2hhx", data)
}
let token = tokenParts.joined()
logger.log.debug("Device Token: \(token)")
let realm = RealmController()
let user = realm.getLoggedInUserObject()
// Send push token to server
if let user = user {
let email = user.email!
let serverController = ServerController.serverController
serverController.sendPushToken(token: token, email: email) { status in
if status == 201 {
// ... some code here ...
} else {
// ... some code here ...
}
}
}
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
logger.log.debug(error)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
logger.log.debug(userInfo)
let aps = userInfo["aps"] as! [String: AnyObject]
if aps["content-available"] as? Int == 1 {
// .... some silent push tasks here ....
}
}
}
Final UPDATE 2017-10-31
Apple just had its official (Halloween) release of iOS 11.1
UPDATE 2017-10-09
Apple released iOS11.1 beta 2 today. Again they mentioned in their Release Notes the following note:
Notifications Resolved Issues
Silent push notifications are processed more frequently. (33278611)
I'm going to test again this beta 2 version and update this answer for your information.
UPDATE - Testing -> After some testing with different scenarios this bug seems to be fixed within the latest iOS11.1 beta 2 version. Now we can only wait for the official release. In some forums they assume that Apple will release iOS11.1 in late October.
Older post
I investigated a lot of time the last week to look for an answer regarding this issue. After reading the apple release notes (incl. the deprecated, changed and new functions) I tested the following situation:
I added the empty function to my AppDelegate
and now the silent push works again both in foreground and also in background:
func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
logger.log.debug("Perform Fetch with completion handler TEST")
}
I'm not sure if this 'workaround' is related to the issue, that the following function application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)
is not called in iOS11.
Nevertheless you can give it a try and give me feedback, if you identify the same behavior.
UPDATE 2017-09-25
The 'silent push' works now in my case in foreground and background mode, but not, if the app is suspended either from the user or from the OS. So this issue is still open and not fixed - any help appreciated!
For more information see also this thread:
Silent pushes not delivered to the app on iOS 11
UPDATE 2017-10-05
Apple released iOS11.1 beta some days ago. They mentioned in their Release Notes the following:
Notifications Resolved Issues
Silent push notifications are processed more frequently. (33278611)
Some developers are saying that the issue is fixed with this beta, other developers say that the issue is still present within some circumstances. Now it would be interesting when Apple is launching iOS11.1 for the customers.
What you experience is actually a well-documented behaviour rather than a bug.
Apple's documentation says:
"The system treats silent notifications as low-priority. You can use them to refresh your app’s content, but the system doesn't guarantee their delivery. In addition, the delivery of silent notifications may be throttled if the total number becomes excessive. The actual number of silent notifications allowed by the system depends on current conditions, but don't try to send more than two or three silent notifications per hour."
In summary, silent notification is not guaranteed to wake up your app. Why? The more often the app in the background on the user's device is woken up, the higher the battery consumption is.
According to IBM's statement, it says "With the advent of iOS 11, Apple has introduced changes in the way they handle certain kinds of push messages. This was done to improve battery life, but comes at a cost of user experience that is likely to affect your app." You can find more details here.