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
Why does your Business need a Mobile App?

Why does your Business need a Mobile App?

Every business is going digital. The majority of users access from their smart phones for searches. Not only big brands, but small and medium-sized businesses will need mobile app for an effective mobile strategy. Proficient mobile app brings added value in the user’s life.

(more…)


Tags: Advertising, Business Apps, iOS Application Development Services, iPhone Application Development Company, iPhone Apps Development India, Mobile Apps Development, Mobility, Online Marketing, Small Business
Share
How building an iPhone app can improve your Business?

How building an iPhone app can improve your Business?

iPhone has brought a revolution to the business domains. People spend most of the time on their devices so it has become very necessary to brand your business on iPhone through apps.

There are already more than 1.08 billion Smartphone users in the world, out of which, 91.4 million are from the United States. iPhone users spend an average of 1 hour and 15 minutes on their phones daily, as opposed to 49 minutes for Android users. And in 2014 it is projected people would start using their iPhone instead of their laptops. (more…)


Tags: Advertising, Business Apps, iOS Application Development Services, iPhone Application Development Company, iPhone Apps Development India, Mobile Apps Development, Mobility, Online Marketing, Small Business
Share
Share