0

I want notification at 2:00 pm and 6:00 pm even if app is closed.

How to check for particular time at which I want to fire local notification and where should I write that code in my code in iOS?

please suggest me a code in Objective-C.

Should I use this method?

- (void)application:(UIApplication *)application 
didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler

If yes then what should I write in this method for getting notification at particular time.

aircraft
  • 25,146
  • 28
  • 91
  • 166
sp309
  • 150
  • 1
  • 10

3 Answers3

1

When app is suspended or in background a delegate method didReceiveLocalNotification called and local notification comes inside:

-(void) application:(UIApplication *)application 
        didReceiveLocalNotification:(UILocalNotification *)notification  

You need to implement above method in appdelegate.

Please remind didReceiveRemoteNotification method only called whenever app getting notification through server called as push notifications or remote notification

vaibhav
  • 4,038
  • 1
  • 21
  • 51
1

You should not use didReceiveRemoteNotification method for getting local notification.

You should use didReceiveRemoteNotification method for getting push notification.

We must know the below things

When app is not running or when app is closed state

If the app is not frontmost and visible, the system displays

the alert

message, 

badges

the app, and plays a sound—whatever is specified in the notification. If the notification is an alert and the user taps the action button (or, if the device is locked, drags open the action slider), the app is woken up or launched. (If the user taps one of the custom actions you specify using the category property, the app is woken up or launched into the background.) In its application:didFinishLaunchingWithOptions: method, the app delegate can obtain the UILocalNotification object from the launch options dictionary using the UIApplicationLaunchOptionsLocalNotificationKey key. The delegate can inspect the properties of the notification and, if the notification includes custom data in its userInfo dictionary, it can access that data and process it accordingly. On the other hand, if the local notification only badges the app icon, and the user in response launches the app, the application:didFinishLaunchingWithOptions: method is called, but no UILocalNotification object is included in the options dictionary. When the user selects a custom action, the app delegate’s application:handleActionWithIdentifier:forLocalNotification:completionHandler: method is called to handle the action.

Apple API reference

When Applicaton is Running in Foreground State

If the app is foremost and visible when the system delivers the notification, the app delegate’s application:didReceiveLocalNotification: is called to process the notification. Use the information in the provided UILocalNotification object to decide what action to take. The system does not display any alerts, badge the app’s icon, or play any sounds when the app is already frontmost.

applicationDidReciveLocalNotification

Also

iOS: If app is in background and local notification is arrived; which method will called automatically?

Community
  • 1
  • 1
user3182143
  • 9,459
  • 3
  • 32
  • 39
  • i have set alert and in alert message i have store notification which coming from uilocalnotification.now tell me how to fire notification through alert when app is closed? – sp309 Dec 28 '16 at 10:13
  • If the notification is an alert and the user taps the action button,the app is woken up or launched.In its application:didFinishLaunchingWithOptions: method, the app delegate can obtain the UILocalNotification object from the launch options dictionary using the UIApplicationLaunchOptionsLocalNotificationKey key. – user3182143 Dec 28 '16 at 10:17
  • http://stackoverflow.com/questions/35034074/does-launchoptions-uiapplicationlaunchoptionslocalnotificationkey-contain-nsdi – user3182143 Dec 28 '16 at 10:20
  • but how to set on particular fixed time daily?that is my question.for set on particular time,in which method i have to code and what to check? – sp309 Dec 28 '16 at 10:21
  • http://stackoverflow.com/questions/39941778/how-to-schedule-a-local-notification-in-ios-10-objective-c – user3182143 Dec 28 '16 at 10:24
  • yeah this is code but how to check condition for current time and notification time is same? – sp309 Dec 28 '16 at 10:28
  • First check http://stackoverflow.com/questions/27036783/how-to-fire-daily-localnotification-at-specific-time-in-ios and http://stackoverflow.com/questions/33301621/how-to-schedule-daily-local-push-notification-in-ios-objc – user3182143 Dec 28 '16 at 10:29
  • http://stackoverflow.com/questions/25030060/schedule-uilocalnotification-everyday-at-specific-time – user3182143 Dec 28 '16 at 10:32
  • Finlay this one http://stackoverflow.com/questions/4363847/how-to-set-local-notification-repeat-interval-to-custom-time-interval – user3182143 Dec 28 '16 at 10:33
0

application:didReceiveLocalNotification: is now deprecated because the class UILocalNotification is deprecated.

Use UNNotification instead.

Spartacus9
  • 164
  • 2
  • 18