Setting reminders and check condition? - ios

It may be simple but i am looking for a specific solution inside a problem.
I would like to let user set a reminder ,but when the time is come, to check some condition in my server before i show him the notification message .
Also, i would like to have the ability to cancel all reminders in one line.
Right now i am using the notification alarm like this :
UILocalNotification * notification = [[UILocalNotification alloc] init];
notification.fireDate = newDate;
notification.repeatInterval = NSCalendarUnitDay;
notification.alertTitle=#"Reminder";
notification.alertBody = message;
notification.soundName=#"shake.mp3";
notification.userInfo=med;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
and cancel all of them with this :
[[UIApplication sharedApplication] cancelAllLocalNotifications];
If the user hit the message i have a callback function. but i would like to check before i show the message-for a condition.
How do you set a reminder that fires a callback function,so you can also control the reminders,the specific messages,the condition of the app when user hit the message ( background/foreground etc) ?

Related

silent notification to alert in ios?

I'm sending a silent notification to a user that gets picked up trough "didReceiveRemoteNotification fetchCompletionHsndler" where I want to check som conditions and if it returns "true" for thoese want to make notificaton visible to a user -any idea on how can I accomplish that?
Yes, there are 2 ways for that.
If your condition returns true then:
1) Your app is an active state then use any third party/alert to show that navigation content.
2) Your app is in the background then fire local notification with exact content of the silent notification.
like this:
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = [[NSDate date] dateByAddingTimeInterval:1]; // will fire notification after 1 second
notification.alertBody = #""; // pass your body text here
[[UIApplication sharedApplication] scheduleLocalNotification:notification];

Reset or clear iOS app badge without any app interactions like open the app or push notification

Any possibility to reset/clear app badge without any app interactions such as opening the app or any push/local notifications. My need is, I want to reset my app badge starting off every day without even opening the app or with any notifications.
You can schedule local notification for end of day with badge count equal 0. Check this out Updating iOS badge without push notifications
I solved this problem with the help of this solution. The working code is:
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
NSCalendarUnit unitDay = NSCalendarUnitDay;
localNotification.repeatInterval = unitDay;
localNotification.fireDate = fireDate;
localNotification.applicationIconBadgeNumber = -1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
Local notification has no alertBody, so local notification will not display upfront.
If need to show alertBody then add localNotification.alertBody = #"Your notification alertBody";.
Thanks for the answer.

Repeating and canceling UILocalNotification

I want to have a UILocalNotification firing in my application every minute for a variable number of times and after that, I want to cancel it.
I'm trying to find a parameter that would enable me to do that.
1) Scheduling notification
Note the .repeatInterval property value.
UILocalNotification *reminder = UILocalNotification.new;
reminder.fireDate = fireDate;
reminder.timeZone = [NSTimeZone systemTimeZone];
reminder.alertBody = #"Your alert message";
reminder.alertAction = #"Your alert action";
reminder.soundName = UILocalNotificationDefaultSoundName;
reminder.repeatInterval = NSMinuteCalendarUnit;
[[UIApplication sharedApplication] scheduleLocalNotification:reminder];
2) Handling notification (AppDelegate)
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
// custom handling code
}
Note: in iOS 8 you have to register for local notifications for the delegate methods to be called.
3) Canceling UILocalNnotification
[[UIApplication sharedApplication] cancelLocalNotification:reminder];
4) Notification distinction
To keep track of how many times a notification has been received, you have to uniquely identify your notification(s). You can do that by making use of UILocalNotification instance .userInfo property.
Example
UILocalNotification *reminder = UILocalNotification.new;
...
reminder.userInfo = [NSDictionary dictionaryWithObject:#"custom value" forKey:#"notificationUniqueId"];
...
Then, when you receive your notification in delegate method written in 2), you can check for notification unique id that you stated in userInfo dictionary. Knowing that, you are able to keep track how many times a UILocalNotification has been fired and cancel it when appropriate.
Hope that helps!

How to show UIAlertView for local notification instead of the label-notification which appear at top of the screen in ios7 ?

because I think beyond iOS5 they remove UIAlertView instead of one label appear at the top of screen which I don't want,I am using this code but it doesn't trigger alertview, i need old look of localnotification.
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] [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
please Help, Thanks in Advance!
The notification alert style cannot be changed in our application programmatically. This alert styles shown based on the user wish. If you see in iPhone settings-> notification center, you may see all the applications registered for notifications. The user can change the alert style for each application based on their wish. This is not in our hand.
This is not up to the control of the app or the developer (using public API). The user can decide if and how to receive notifications from your app. You may suggest you your user on first launch/tutorial/help that for best experience, you may want to enable alerts instead of banners and perhaps display visual cues on how to do it.

How to display Alertview with UILocalNotification instead of just Badge and make it stay unless users presses a button on UIalertView?

In my app, I am trying to create an Alarm but the only problem is with ios6 UILocalnotification is been converted to badge instead of UIAlertView.
Here's the code i am using:
UILocalNotification * notif = [[UILocalNotification alloc]init];
notif.fireDate = date;
notif.alertAction = #"Snooze";
notif.repeatInterval = NSDayCalendarUnit;
notif.alertBody = #"Time to wake up";
notif.soundName = #"client_song.mp3";
[[UIApplication sharedApplication]scheduleLocalNotification:notif];
Sorry, you don't get any choice about that. The user is allowed to specify (in the Settings app) that a local notification from your app should appear as an alert, or as a banner, or not appear at all - and you can't do anything about it. If you don't like that, don't use a local notification...

Resources