Push Notification issue with FCM in iOS13 - swift

I am using FCM for push notifications. I used to refresh the content of the app using the below method
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> Void) {
Now with iOS13 this method is not firing anymore. I have included apns-push-type and apns-priority as well.

I found the issue.
UIApplication.shared.registerForRemoteNotifications()
this has to run for every launch. Better to keep this in didFinishLoadingWithOptions method. In my previous version, I used to call this for the first time but looks like it has to be for every launch.
and make sure set delegates for notification and messaging also.
UNUserNotificationCenter.current().delegate = self
Messaging.messaging().delegate = self

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> Void) {
if #available(iOS 13.0, *) {
// your code
completionHandler(UIBackgroundFetchResult.newData)
} else {
}
}
also check your APNS certificate on FCM, it must .p12 type must be available in keychain that you are using for your current XCode version

Related

Handle notification dismiss action when app is on the background

I'm trying to listen user clear push notification action. I've the code below, It's working when the app is on the foreground but when i put the app on the background it doesn't go into that function. Is there any way that i can do some coding when the user clear the notification on the background state?
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: #escaping () -> Void) {
if(response.actionIdentifier == UNNotificationDismissActionIdentifier){
...
//I need to do some coding here!
}
}
I use this for receiving remote notifications behind the scenes:
extension AppDelegate: UNUserNotificationCenterDelegate {
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> Void) {
// Process this userInfo dictionary
processNotification(dictionary: userInfo)
}
In my willFinishLaunchingWithOptions in AppDelegate I call this:
fileprivate func setupAPN(application: UIApplication) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
// For iOS 10 data message (sent via FCM)
MobilePlatformPush.setRemoteDelegate(delegate: self)
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { _, _ in }
application.registerForRemoteNotifications()
}

iOS: didReceiveRemoteNotification is not being called when the app is in background

Despite having "remote notification" in background modes, the app does not seem to do anything when the app is in the background. All I want to do is updating the badge number when the app is closed or terminated (like what Twitter app does).
func application( _ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> Void) {
UIApplication.shared.applicationIconBadgeNumber = 99 // just to test
completionHandler(.newData)
}
Background Mode settings:
When the app is in foreground it updates the badge, this is the payload:
{
"aps": {
"badge": 4,
"content-available": 1,
"mutable-content": 0
}
}
But when it's in background it does nothing. Should it not update the badge?

Swift Push Notifications but only sending 'content-available' do I need to ask user permission

Im developing a swift app that uses data from a server.
To initiate the 'get data' command I'm using APNS with a message body of
$body['aps'] = array(
'content-available' => 1
);
This obviously triggers
func application(
_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> Void) {
and I then call function to get server data.
As im not showing a notification do I have to ask the user for permission?
i.e.
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {

didReceiveRemoteNotification not called swift 3 iOS 10

I made a lot of search during many days (20 posts+) but I didn't the solution to my problem.
I have an application which receive push notification, I can receive those remote notifications but when I tap on it, the delegate "didReceiveRemoteNotification" is not called (I want to intercept the payload to do action in fonction of it).
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: #escaping (UIBackgroundFetchResult) -> Void) {
print("test")
}
In advance, thanks for help.
The didReceiveRemoteNotification method does not fire when the user launches the app by tapping on the notification and not when the notification is received, never.
Sorry for my bad english and if you have question, don't hesitate.
First import UserNotification framework and then implement UNUserNotificationCenterDelegate in ios10 to support push notification in ios10
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: #escaping () -> Void) {
//Handle notification tap
}

Swift. create a banner while receive a remote notification when screen is not in background

Below are the code I have when receive notification. I know I can use PFPush to create a alert, but I feel that it is not a good way. Is there a way to create a banner instead of alert?
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
NSNotificationCenter.defaultCenter().postNotificationName("getMessage", object: nil)
if application.applicationState == UIApplicationState.Active {
//PFPush.handlePush(userInfo)
}
completionHandler(UIBackgroundFetchResult.NewData)
}