Difference between push notification and nsnotifcation centre in iOS sdk - ios

I have question about push notification and the Notification Center. I have built an app and now I want to support notification the the time hits 0 I'm doing like countdown app shows the release date for games and title.
Should I use nsnotifcation center or push notification

You dont need Push Notifications you can acheive that with UILocalNotification. For Push Notifications you need coordination with server but for UILocalNotification you can do it inside your application so better try to use UILocalNotification
For simple UILocalNotification
UILocalNotification* localNotification = [[UILocalNotificationalloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:60];
localNotification.alertBody = #"Your alert message";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
For UILocalNotification with timers
// Get the current date
NSDate *pickerDate = [self.datePicker date];
// Schedule the notification
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = pickerDate;
localNotification.alertBody = self.itemText.text;
localNotification.alertAction = #"Show me the item";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
// Request to reload table view data
[[NSNotificationCenter defaultCenter] postNotificationName:#"reloadData" object:self];
you can study in detail in here http://www.appcoda.com/ios-programming-local-notification-tutorial/

Related

UILocalNotification launched every minute util user click it

If I set my notification like the code below, it would launch alarm every minute. However, it gets triggered even my alarm is set behind the current time. For example, the current time is 12:00 and the alarm time is 9:00, it still gets triggered because kCFCalendarUnitMinute is a loop.
How can I get the function as my title description?
UILocalNotification *localNotification = [UILocalNotification new];
localNotification.userInfo = #{#"status":#"alarm",#"note":noteString,#"index":#(index)};
localNotification.fireDate = dateToFire;
localNotification.alertTitle = #"Alarm";
localNotification.alertBody = #"Wake Up!";
localNotification.soundName = #"myTone.m4a";
localNotification.alertAction = #"View";
localNotification.repeatInterval = kCFCalendarUnitMinute;
localNotification.regionTriggersOnce = true;
localNotification.applicationIconBadgeNumber =
[UIApplication sharedApplication].applicationIconBadgeNumber + 1;
localNotification.timeZone = [NSTimeZone systemTimeZone];
// To set the local notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

How to notify UILocalNotification for every two week [duplicate]

This question already has answers here:
how to set local notification for every two weeks
(2 answers)
Closed 6 years ago.
Good Morning,
How to notify localNotification for every two weeks (14days) a notification.
- (void)applicationDidEnterBackground:(UIApplication *)application {
timer = [NSTimer scheduledTimerWithTimeInterval:60*60*24*14 target:self selector:#selector(getNotifiedForTwoWeeks:) userInfo:nil repeats:YES];
}
-(void)getNotifiedForTwoWeeks:(id)userinfo{
// Schedule the notification
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate date];
localNotification.alertBody = #"Notification Message";
localNotification.alertAction = #"Show me the item";
localNotification.timeZone = [NSTimeZone timeZoneWithName:#"GMT"];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
Please let me know is this implementation is correct or not?
Is there any alternative way i can do the best for notifying a LocalNotification message for every two weeks.
Your valuable inputs are appreciated!
When your app will enter to background the system will suspend it after some time and your NSTimer will not schedule.
So you can schedule for every 14 days notification through declare a fireDate and repeatInterval properties in UILocalNotification
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate dateByAddingTimeInterval:60*60*24*14];
localNotification.alertBody = #"Notification Message";
localNotification.alertAction = #"Show me the item";
localNotification.timeZone = [NSTimeZone timeZoneWithName:#"GMT"];
localNotification.repeatInterval = NSDayCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

Using Textbox for local notifications

I'm trying to make it so a user can type in the text box what they need to be reminded of for a alarm to go off but if they type it in the notification doesn't show that reminder how do i fix this
You have to setup correctly your notification. Here an example with objective-c where I send a notification after 10 second.
- (IBAction)createNotification:(id)sender {
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
localNotification.alertBody = #"Put Here your reminder text";
localNotification.category = #"myCategory";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
The alertBody is the text you can customize and can be the text from a textbox or another control. I hope this can help you

Scheduled local notification and timezone changes in iOS

I have this method in my app to fire scheduled local notifications:
- (void)scheduleNotificationForTime:(long long)atTime
{
NSDate *fireDate = [DatesMngr getDateFromLongLong:atTime];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = fireDate;
localNotif.timeZone = [NSTimeZone localTimeZone];
localNotif.alertBody = #"Active Status";
localNotif.alertAction = #"View Details";
localNotif.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] cancelAllLocalNotifications];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
It works fine if user does not change her timezone in her device's Settings, but the notification is not launched if she changes the timezone after it has been already scheduled but not launched yet. I've also tried with [NSTimeZone defaultTimeZone] with no success. Is there any way to detect these timezone changes and refresh the fireDate for already scheduled local notifications?
Thanks
You can do it in 2 ways
implement the following method in your appdelegate
(void)applicationSignificantTimeChange:(UIApplication *)application
2
. Register for UIApplicationSignificantTimeChangeNotification in notificationcenter
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(handleTimeChange:)];

Register for Local Notification

I am developing an IOS application with phonegap and need to set local notification for it which will repeat on every friday and specified time
Also there is requirement that user will decide to receive or not the local notification
I recommend you read the following article on the topic which i found very helpful
http://useyourloaf.com/blog/2010/7/31/adding-local-notifications-with-ios-4.html
- (void)scheduleNotification {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
UILocalNotification *notif = [[UILocalNotification alloc] init];
notif.fireDate = [datePicker date];
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.alertBody = #"Body";
notif.alertAction = #"AlertButtonCaption";
notif.soundName = UILocalNotificationDefaultSoundName;
notif.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
[notif release];
}
}
This is just a basic outline of how it works but starting from this you should be able to schedule a notification.

Resources