Execute Code When Recieve Push Notification When App Is Not Running
I am working on a reminder app.The app will show notifications at particular times which is set by the user.I have used local notifications to show the reminder.
The problem is I want to run some codes when it receives the local notifications even if the user does not tap on the notification. Is there any way to do this in swift ?
I believe you should add method
application(_ application: UIApplication, didReceive notification: UILocalNotification) inside your AppDelegate.swift. The code you want to be implemented should be there. The code will be executed even the user does not tap on the notification. But anyhow, the app should be running.
Here is an extract from apple docs:
If the app is not active in the foreground when the notification fires, the system uses the information in the UILocalNotification object to determine whether it should display an alert, badge the app icon, or play a sound. If the app is running in the foreground, the system calls this method directly without alerting the user in any way.
You might implement this method in your delegate if you want to be notified that a local notification occurred. For example, a calendar app might use local notifications to alert the user to upcoming events.
If the user chooses to open the app when a local notification occurs, the launch options dictionary passed to the application(:willFinishLaunchingWithOptions:) and application(:didFinishLaunchingWithOptions:) methods contains the localNotification key. This method is called at some point after your delegate’s application(_:didFinishLaunchingWithOptions:) method.
- → Function Undefined in Axios promise
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Click to navigate on mobile devices
- → Playing Video - Server is not correctly configured - 12939
- → How to allow api access to android or ios app only(laravel)?
- → Axios array map callback
- → Access the Camera and CameraRoll on Android using React Native?
- → Update React [Native] View on Day Change
- → Shopify iOS SDK - issue converting BuyProductVariant to BuyProduct
- → BigCommerce and shopify API
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → React Native - Differences between Android and IOS
- → What is the difference between React Native and React?