0

Thanks to Alex, I know now that it fails due to a bug in iOS 11 and the expected solution will be shipped with iOS 11.2.

I didnt know that when i wrote it and nevertheless, the question shows necessary steps to have silent notifications working.

At the moment of writing it was missing that the services enabled in the AppId of the developer console, must have push notifications enabled and its certificates, for develop and distribution (given the case).

Payload from server like this one:

$body = array( 
        'aps' => array( // Create the payload body
            'content-available' => 1,
        )
    ); 

Wont produce anything in the app (and i mean to call the delegates)

The appDelegate:

class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {...}

Which fn, didReceiveRemoteNotification is not called, and the UNUserNotificationCenter didReceive fn is also not called.

Fn didfinishlaunch... includes:

var center = UNUserNotificationCenter.current()
center.delegate = self
center.setNotificationCategories([loadActionAndCategoriesForNotifications()])

The notification registration in appDelegate is as follows, also in didfinishlaunch... fn:

if #available(iOS 10.0, *)
    {
        let options: UNAuthorizationOptions = [.alert, .badge, .sound]
        // request authorization
        center.requestAuthorization(options: options) {
            (granted, error) in
            if !granted {
                l.i(self.TAG, "registerNotifications: request for authorization went wrong")
            }
            if granted {
                l.i(self.TAG, "registerNotifications: request for authorization GRANTED.")
                DispatchQueue.main.async {
                    l.i(self.TAG, "registerNotifications NOW WILL DO REMOTE REGISTRATION.")
                    UIApplication.shared.registerForRemoteNotifications()
                }
            }
            if error != nil{
                l.i(self.TAG, "registerForLocalNotification ERROR: \(error!.localizedDescription)")
            }
        }

    } else {
        // Fallback on earlier versions
        UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: [.sound, .alert, .badge], categories: nil))
        UIApplication.shared.registerForRemoteNotifications()
    }

Registration is doing fine, and I always receive in didRegisterNotif... the corresponding deviceToken.

And on Target capabilites, push notification is ON and Background Modes has Background fetch and Remote notifications checked.

If i add "'badge' => 3," to the aps payload, foreground willPresent fn is called so i can further process the notification data.

In background, curiously, ( width 'badge' => 3, in aps) the badge is updated! BUT I am expecting didReceiveRemoteNotification or didReceive to handle it so I can process and send a local notification, but it does not happen, they are never called...

I am running out of ideas here after reading i think almost any question i found...

user968865
  • 97
  • 2
  • 17
  • Which operating system are you using for testing? iOS9, iOS10 or iOS11? – AlexWoe89 Oct 08 '17 at 14:28
  • 1
    just for your information: this behavior is a bug in ios11 (incl. 11.0.1 & 11.0.2) It should be fixed in the new version 11.1 which is currently in beta state. see also the following stackoverflow topics: https://stackoverflow.com/questions/46330053/ios11-swift-silent-push-background-fetch-didreceiveremotenotification-is-not and https://stackoverflow.com/questions/44796613/silent-pushes-not-delivered-to-the-app-on-ios-11 – AlexWoe89 Oct 08 '17 at 16:33
  • @Alex 11.0.1. thx... – user968865 Oct 08 '17 at 16:36

0 Answers0