69

I am getting an error after adding this code from parse.com:

- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    if (application.applicationState == UIApplicationStateInactive) {
        [PFAnalytics trackAppOpenedWithRemoteNotificationPayload:userInfo];
    }
}

I don't really understand what is going on, but I am getting this warning in the log:

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

I think adding in your plist file UIBackgroundModes - remote-notification would fix the problem,

But when I do that, it changes the words to the follow:

Required Background Modes -> App downloads content in response to push notifications

Which my app doesn't do, so I am confused as to why I am doing this in the first place.

5 Answers 5

212

If you don't want to manually add key in your .plist file then here's a graphical version of @MurraySagal's answer, follow the steps from 1 to 7 and you'll be done. :)

enter image description here

Note: If you can't read out the steps, you can zoom out your current tab by using combination of Command++ (for zoom in) and Command+- (for zoom out). If Command won't work, you can try with Ctrl.

2
  • 1
    This fixed the GCM issues I was having. This is a good way of doing it
    – MNM
    May 18, 2016 at 1:02
  • 1
    perfect solution! Sep 14, 2016 at 12:14
38

I think @djshiow is not solving your problem.

You need to add the following in your info.plist file:

remote-notification

1) Add a new row and, on the left column, select Required background modes.

2) On Item 0 row, click on the right column and type: remote-notification. Press Enter.

Source: http://hayageek.com/ios-silent-push-notifications/

31

If you don't intend to fetch data in response to a remote notification I think you can implement this delegate method:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 

e.g.

- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
    if (application.applicationState == UIApplicationStateInactive) {
        [PFAnalytics trackAppOpenedWithRemoteNotificationPayload:userInfo];
    }
}

instead of the current one you're using.

3
  • This is exactly what I needed: if you follow the parse guide(s), the assumption is you want to background-download data via pushes. I don't. So this answer is correct for me.
    – xaphod
    Mar 28, 2015 at 21:57
  • 2
    The main difference being that you are NOT implementing the fetchCompletionHandler: version of the didReceiveRemoteNotification: methods.
    – pkamb
    Aug 12, 2015 at 19:23
  • 5
    In iOS 10 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo is deprecated
    – Giorgio
    Jan 24, 2017 at 11:41
22

In Xcode 6:

  • In the Project Navigator click the project
  • In the Projects and Targets list click the target.
  • Click Capabilities
  • Expand and turn on Background Modes
  • Click Remote Notifications

This will add the Required background modes key and App downloads content in response to push notifications value to info.plist.

0

When you use the new didReceive... method you are expected to do two things:

  1. Add the necessary entry in your plist
  2. Add a completion handler that will handle the event for handling the data

If you do not want to download any data, you can add this to your didReceive... method

completionHandler(.NoData)

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.