Sending Local Notifications in iOS

Want to learn how to send local notifications in IOS? Vizteck is giving you a step-by-step detailed guide for it.

image

Software Development Services

image

May 5, 2014

image

Mah Noor

image

 

A local notification is a way of notifying users without any Internet and server-side implementation. You can specify the date and time when a 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 the foreground.

 

123.webp

456.webp

789.webp

709.webp

 

PURPOSE | What are we Trying to do?

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

IMPLEMENTATION | Sending Notifications.

0000.webp

Receiving Local Notifications

In AppDelegate.m you need to reset the app icon count to 0 when local notifications are read so replace the didFinishLaunchingWithOptions method with the below code.

 - (BOOL)application: (UIApplication*) application didFinishLaunchingWithOptions: (NSDictionary*) launch options

 { 

UILocalNotification* localNotification =

[launchOptionsobjectForKey:  UIApplicationLaunchOptionsLocalNotificationKey]; 

if (local notification)

{ application.applicationIconBadgeNumber = 0; } returnYES; }  

Local notifications are only received when your app is not running in the foreground. If you want to show a notification in the alert when the app is active (in the foreground state) then add the 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 a notification after 30 seconds.


 

Islamabad, Pakistan

Floor 2, Building 145, Civic Center Bahria Town Phase 4, Islamabad, Pakistan

USA

1 squire armor road, windham, NH,03076