I've tried various combinations of the following:
- An empty alert passed in the aps payload
- An empty sound passed in the aps payload
- content_available: true
- content-available: 1
Priority is set to high. I have background fetch and remote notifications enabled in background modes in my target capabilities.
This is what my payload looks like:
JsonObject jGcmData = new JsonObject();
jGcmData.addProperty("to", "/topics/global");
jGcmData.addProperty("priority", "high");
JsonObject jData = new JsonObject();
jData.addProperty("id", nObj.id);
jData.addProperty("title", nObj.title);
jData.addProperty("body", nObj.body);
JsonObject apsData = new JsonObject();
apsData.addProperty("content-available", "1");
apsData.addProperty("alert", "");
jGcmData.add("aps", apsData);
jGcmData.add("data", jData);
The notification comes in as soon as I open the app but not in the background.
It looks like this:
[AnyHashable("body"): NTCIP Example Unit: now showing WALNUT TREE (Tue Nov 15 14:01:30 EST 2016), AnyHashable("id"): idhere, AnyHashable("collapse_key"): do_not_collapse, AnyHashable("from"): /topics/global, AnyHashable("title"): Notification of message change]
My AppDelegate functions for the foreground and background notifications when received:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler handler: @escaping (UIBackgroundFetchResult) -> Void) {
print("background notification received: \(userInfo)")
GCMService.sharedInstance().appDidReceiveMessage(userInfo);
NotificationCenter.default.post(name: NSNotification.Name(rawValue: messageKey), object: nil, userInfo: userInfo)
handler(UIBackgroundFetchResult.noData);
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
print("foreground notification received: \(userInfo)")
GCMService.sharedInstance().appDidReceiveMessage(userInfo);
NotificationCenter.default.post(name: NSNotification.Name(rawValue: messageKey), object: nil, userInfo: userInfo)
}
I never see application(didReceiveRemoteNotification:::fetchCompletionHandler) called.
Please help!