How to clear the remote notification in your app?
You need to set the IconBadgeNumber to 0 and cancel the current notifications. I never did in swift but I think the code for it would be as bellow:
application.applicationIconBadgeNumber = 0
application.cancelAllLocalNotifications()
Swift 5
UNUserNotificationCenter.current().removeAllDeliveredNotifications()
iOS push notification: how to detect if the user tapped on notification when the app is in background?
OK I finally figured out.
In the target settings ➝ Capabilities tab ➝ Background Modes, if you check "Remote Notifications", application:didReceiveRemoteNotification:
will get triggered as soon as notification arrives (as long as the app is in the background), and in that case there is no way to tell whether the user will tap on the notification.
If you uncheck that box, application:didReceiveRemoteNotification:
will be triggered only when you tap on the notification.
It's a little strange that checking this box will change how one of the app delegate methods behaves. It would be nicer if that box is checked, Apple uses two different delegate methods for notification receive and notification tap. I think most of the developers always want to know if a notification is tapped on or not.
Hopefully this will be helpful for anyone else who run into this issue. Apple also didn't document it clearly here so it took me a while to figure out.
Related Topics
Disable Warning Dialog If Bluetooth Is Powered Off iOS
Ios-8 and Later - Uitableview Inside an Uialertcontroller
Select Items Programmatically in Uicollectionview
How to Register Undomanager in Swift
How to Use Phcachingimagemanager
iOS Google Sdk Map Cannot Create Dotted Polylines
Regex to Get String Between Two % Characters
Nsindexpath? Does Not Have a Member Name 'Row' Error in Swift
Cannot Get My Location to Show Up in Google Maps in iOS 8
Insert String at Cursor Position of Uitextfield
How Is Filters Uiscrollview/Uicollectionview in Apple's Photos App Implemented That It Opens So Fast
Reordering Uitableview Without Reorder Control
Swift - Add Gesture Recognizer to Object in Table Cell
Allow Full Access Check in Keyboards iOS10
Ble Device Keep Connect with iPhone When Application Terminate