Set up UILocalNotification in iOS Swift/Objective C

Set up UILocalNotification in iOS Swift/Objective C

 

UILocalNotification helps to schedule specific notification for the user on specific date & time. As the name suggests that its handled & called from inside the application locally. So it can work without internet connection.

Its used in an application for various purpose like :

  • Keeping user active into application & make sure app usage increases
  • Notify for some reminders in the application
  • Used as a reminder feature inside the application
  • Keep highlighting for the features inside the application
  • Daily usage reminder for the application

So here is the tutorial about how we can create a UILocalNotification & manage it.

Objective C :

 

Create new notification :

-(void)doCreateLocalNotification {

NSDate *now = [NSDate date];

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:now];

[components setHour:18];

[components setMinute:1];

[components setSecond:10];

NSDate *firedate = [calendar dateFromComponents:components];

UILocalNotification *notification = [[UILocalNotification alloc] init];

notification.fireDate = firedate;

notification.alertBody = @”Hey how are you ? Have you used application today ?”;

notification.repeatInterval = NSCalendarUnitDay;

[[UIApplication sharedApplication] scheduleLocalNotification:notification];

}

Destry all local notifications :

-(void)doDestryNotification {

[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];

[[UIApplication sharedApplication] cancelAllLocalNotifications];

}

Read more: Healthy iOS Development Tips & Tricks

Swift :

 

Create new notification :

func doCreateReminder() {

let dateToFire = NSDate().addingTimeInterval(60*60*24*7)

let notification = UILocalNotification()

notification.fireDate = dateToFire as Date

notification.alertBody = NSLocalizedString(“localalert”, comment: “”)

let dict:NSDictionary = [“type” : “reminder”]

notification.userInfo = dict as! [String : String]

notification.repeatInterval = NSCalendar.Unit(rawValue: UInt(0))

notification.soundName = UILocalNotificationDefaultSoundName

UIApplication.shared.scheduleLocalNotification(notification)

}

Destry all local notifications :

func doDestryAllNotification() {

UIApplication.shared.applicationIconBadgeNumber = 0

UIApplication.shared.cancelAllLocalNotifications()

}

 


Tags: iOS, iOS app, iOS Application Development Services, iPhone Application Development Company, Mobile Apps Development, Update
Share
Facebook Instant Articles feature will give new wings to publishers globally

Facebook Instant Articles feature will give new wings to publishers globally

Social media networking spice up the digital marketing, it is essential to have good number of followers and strong back hand support from social media sites for higher ranking on internet. The most famous social media giant Facebook keep on peak by explore with more awesome features.

(more…)


Tags: facebook, facebook updates, Instant Articles, Latest News, New Feature, Publishers, release date, Social Media, Update
Share
Instagram now Supports Multiple Account Switching in iOS and Android Apps

Instagram now Supports Multiple Account Switching in iOS and Android Apps

Buzzing the News from Social Media!

Most famous app for Photo-sharing, Instagram officially rolls out support for power users and advertisers. After months of testing, Instagram introduce new feature with which users can switch among up to 5 different accounts rather than logging in and out from the same device.

(more…)


Tags: Android update, Instagram, Instagram Update, Latest News, Mobile Apps, New Feature, Photography, Social Media, Update
Share
Share