didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called

i0S Swift Issue

Question or problem in the Swift programming language:

I’ve been trying to implement the fetch completion block with no luck. Whenever I send an APN, xcode still complains that it’s not implemented. Here’s my code

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {

    println("2. User Data", userInfo)

    completionHandler(UIBackgroundFetchResult.NewData)

}

and the warning I am getting in the xcode console is this

Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.

Not sure if I am implementing the right syntax here

How to solve the problem:

Solution 1:

Remove the println or change it to a NSLog, then try again. Most likely the problem is caused because this method is coming to you in the background and not on the main thread. println is much simpler than NSLog, which is thread-safe and been hardened for years and years.

Solution 2:

I had an exact same issue but a totally different solution. The problem of mine is I imported Intercom so people can chat in-app, and seems like it intercepts the notifications and the didReceiveRemoteNotification never got called in my AppDelegate.

I can finally stop banging my head against the wall, hope this can save someone’s time.

Solution 3:

Not sure why, but replacing println with NSLog solved the issue.

Hope this helps!