didReceiveRemoteNotification error for remote-notification

You've implemented -[<UIApplicationDelegate>application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add "remote-notification" to the list of your supported UIBackgroundModes in your Info.plist.

How to resolve this error?

Replies

Having to both implement the method *and* add "remote-notification" to UIBackgroundModes is not itself an error. It's just how it's designed.

Think about it, the method is inside the app. The method is used to receive a notification when the app is in background. The operating system does not scan the code to see what the app might want to do so it can't know that it should deliver notifications to your app when your app is in the background. The app communicates to the operating system through its info.plist. The compiler has figured out that your app, because it contains this method, wants the operating system to deliver notifications to it even while it is in background. But your app hasn't told the operating system about this desire. The compiler is telling you to add the notice to your info.plist.

Post not yet marked as solved Up vote reply of PBK Down vote reply of PBK

Thanks, after I add that, I got the following error, should the completion handler always be called in didReceiveRemoteNotification?


func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any],

fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void)


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

From:


https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623013-application?language=objc


"As soon as you finish processing the notification, you must call the block in the

handler
parameter or your app will be terminated."


Note the "you must call" in the above.

You can add this: inside the <dict>
Code Block  
<key>UIBackgroundModes</key>
<array>
    <string>fetch</string>
    <string>remote-notification</string>
</array>

before <key>UILaunchStoryboardName</key> or some tag related in your Info.plist file

I found two occurences of UIBackgroundModes in our info.plist. The second one did not have remote-notification!

I wonder if I implemented these methods with empty function in our app, but we don't add these keys to our Info.plist, will we get rejected when submit to the App Store?