didReceiveRemoteNotification function doesn't called with FCM notification server
If you are testing with Postman then try changing "content-available": true
to "content_available" : true
. content-available will send notification but it doesn't call didReceiveRemoteNotification
.
Push Notifications are delivered but didReceiveRemoteNotification is never called Swift
I finally found the solution. Alert needs"content_available": true
to be set in the alert definition from the post sending funtion from App2 to App1 or else notifications get delivered but 'didReceiveRemoteNotification` is not called and you can't use 'userInfo'. Hope this will help others as I haven't found much info about this problem. If you're setting the notification with Postman or similars check here didReceiveRemoteNotification function doesn't called with FCM notification server as that's the only post I found on this problem and solved mine.
Thanks to @Ranjani for trying helping me.
let postParams: [String : Any] = [
"to": receiverToken,
"notification": [
"badge" : 1,
"body": body,
"title": title,
"subtitle": subtitle,
"sound" : true, // or specify audio name to play
"content_available": true, // this will call didReceiveRemoteNotification in receiving app, else won't work
"priority": "high"
],
"data" : [
"data": "ciao",
]
]
Swift didReceiveRemoteNotification not called
try once your delegete method in this place
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
call this one
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
print("Recived: \(userInfo)")
completionHandler(.NewData)
}
didReceiveRemoteNotification not called when Firebase is used along with Push framework
This is because Firebase uses swizzling to intercept methods of the AppDelegate.
You should disable it in your app's info.plist:
<key>FirebaseAppDelegateProxyEnabled</key>
<false/>
Actually there is a lot of information about Push Notification in iOS with Firebase on GitHub. You probably will find answers for your further questions there.
didReceiveRemoteNotification not working in the background
Implementing didReceiveRemoteNotification
and didReceiveRemoteNotification:fetchCompletionHandler
is the correct way, but you also need to do the following:
Make sure to register for remote notifications, see documentation here:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
return YES;
}
Also make sure to edit Info.plist
and check the "Enable Background Modes" and "Remote notifications" check boxes:
Additionally, you need to add "content-available":1
to your push notification payload, otherwise the app won't be woken if it's in the background (see documentation here updated):
For a push notification to trigger a download operation, the
notification’s payload must include the content-available key with its
value set to 1. When that key is present, the system wakes the app in
the background (or launches it into the background) and calls the app
delegate’s
application:didReceiveRemoteNotification:fetchCompletionHandler:
method. Your implementation of that method should download the
relevant content and integrate it into your app
So payload should at least look like this:
{
aps = {
"content-available" : 1,
sound : ""
};
}
Related Topics
Uisegmentedcontrol iOS 13 Clear Color
Programmatically Creating Uinavigationcontroller in iOS
How to Use Phcachingimagemanager
Obtaining Bluetooth Le Scan Response Data with iOS
Sprite Kit Sprites Loading Performance Improvement
Uilabel, Uifont and Utf-8 Triangle
App Running on iPad While Its Iphone-Only
iOS Notification When Application Is Closed
Xcode 7 Beta 6, Dyld _Nsarray0_ Crash
How to Default Uilabel Font and Size Using Swift
Objective C- Trouble Updating UI on Main Thread
A Lighter Way of Discovering Text Writing Direction
Programmatically Checking If a Passcode Lock Is Set
Select Items Programmatically in Uicollectionview
How to Reload Tableview of Another Uiviewcontroller in Current Viewcontroller