• Vizteck Author

Sending Local Notifications in IOS

Updated: Oct 29

Local notification is a way of notifying users without any Internet and server side implementation. You can specify the date and time when particular notification will be delivered. Local notifications in iOS are used to notify users by text, sound or calendar event when the app is not running in foreground.


PURPOSE | What are we Trying to do?

Click a button to send a notification that will be delivered after 30 seconds.

IMPLEMENTATION | Sending Notifications.


Receiving Local Notifications

In AppDelegate.m you need to reset app icon count to 0 when local notifications are read so replace didFinishLaunchingWithOptions method with below code. - (BOOL)application: (UIApplication*) application didFinishLaunchingWithOptions: (NSDictionary*) launchOptions { UILocalNotification* localNotification = [launchOptionsobjectForKey:  UIApplicationLaunchOptionsLocalNotificationKey]; if (localNotification) { application.applicationIconBadgeNumber = 0; } returnYES; }  Local notifications are only received when your app is not running in the foreground. If you want to show notification in the alert when app is active (in foreground state) then add below method. - (void) application: (UIApplication*) application didReceiveLocalNotification: (UILocalNotification*) notification { UIApplicationState currentState = [application applicationState]; if (currentState == UIApplicationStateActive) { UIAlertView *notificationAlert = [[UIAlertViewalloc] initWithTitle: @"Local Notifications" message:@"You have a notification.please check"delegate:selfcancelButtonTitle:@"OK" otherButtonTitles:nil]; [notificationAlert show]; } application.applicationIconBadgeNumber = 0; } 

Run your project and click send notification button to Schedule notification after 30 seconds.

#iOS #localnotifications #localnotificationsinIOS #localnotificationsIOS