• Vizteck Author

Sending Local Notifications in IOS

Updated: May 13, 2020

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.

sending_local_notification1b
sending_local_notification2b
sending_local_notification3b
sending_local_notification4b

PURPOSE | What are we Trying to do?

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

IMPLEMENTATION | Sending Notifications.


sending_local_notification5b

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. If you are facing any problem, you can download Complete Project.

#iOS #localnotifications #localnotificationsinIOS #localnotificationsIOS

3 views0 comments