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 : ""
};
}
didReceiveRemoteNotification not called swift
The reason was that I accepted receive notification when I install my app with GoogleService-Info.list from first console. So, if you change the console, of course you change the GoogleService-Info.list, and you should again to accept receive notification!!! If you don't to accept, didReceiveRemoteNotification will not call!
P.S.
In my variant I'm implement notification with swizzling. If you chose the same way, be sure that in your Info.plist file you have property FirebaseAppDelegateProxyEnabled which value setup as YES
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)
}
Related Topics
How to Set Size Leftbarbuttonitem
How to Get a Low Res Image, or Thumbnail from the Alassetrepresentation in Swift
Googlemap API Gives Wrong Coordinates for Direction Between Two Points
Uidocumentinteractioncontroller Does Not Open Other App in iOS 11
iPhone /iOS: Presenting HTML 5 Keyboard for Postal Codes
Why Use Corebluetooth Connectperipheral Did Not Call Delegate Methods in iOS8
How to Use Pod in Notification Service Extension
How to Install Self-Signed Certificates in iOS 11
Why Wkwebview Doesn't Display Videos? - Swift 3
Gkmatchmaker Invite Handler Deprecated
How to Get the Index in Results of a Certain Realm Object
How to Make a Phonegap App for iOS Without Mac
How to Prevent Duplicates in Realmswift List
Nstextattachment Image Not Shown in Nstextview (But in Uitextview)