remove/update notification from lock screen - ios

I use UILocalNotification to show alerts.
I need to show two alerts 2 hours apart.
Right now, my code displays two different notifications on lock screen.
Assume, alerts/notifs were not touched by user during this period.
Is it possible for me to
Either remove the first shown notification from lock screen
Or update the first notification with the contents of second alert/notifcation.

To my understanding, you cannot modify a UILocalNotification once it has been scheduled.
To dismiss an already fired UILocalNotification, try calling the [[UIApplication sharedApplication] cancelAllLocalNotifications];
and then re-add those that were not yet fired.

Related

IOS push notification delete

I use a phone gap plugin and xcode 5.
Lets see the example of the problem:
The application is in background or closed.
I send the notification.
User sees the notification pop up, without clicking on it.
I send another notification.
If user open notification bar it will see two notification actually i want
to delete the previous some how and present to user only the second notification.
The eqvivalent in java is NotificationManage.cancelAll();
For now each/all notification i send are shown when user open notifications bar.
Any help appreciated.
You have (the app has) no control over that.
The user controls how many notifications they see in notification center. Notifications can be removed by the user and will be removed when acted upon (the app is opened from the notification).
You can do this by [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
in the method didReceiveRemoteNotification. In this way notification center will be cleared.

Is it possible to change the display duration of a UILocalNotification?

I need to display a local notification and have it remain on screen longer than the default 4-5 seconds, preferably until the app itself removes it. I've seen other apps (e.g. Pandora) that manage to do this somehow (maybe a push notification?), but I can find no duration property on UILocalNotification or in UIApplication methods like presentLocalNotificationNow:, scheduleLocalNotification:, etc. Neither the documentation nor any of the tutorials I've found address the display time at all. Is this something that just can't be done with local notifications?
A couple of solutions here and I would not recommend either:
1- You can request from the user to go to settings > Notification Center > your app. And change the alert style from Banner (default) to Alerts. This will present the user an alert similar to the alert presented when the app is in the foreground. The user would have to dismiss the alert versus the banner style notification that just appears/disappears. Unless this is a corporate app and you have the users buy in, I would not go that route as this could annoy the user.
2- I tested the sound clip method and yes, if you present a notification with a clip < 30seconds; the notification will stay on the (top of the) screen until the sound clip is finished playing. Having said that, if the user taps any of the volume button (to reduce the sound for example), the notification is immediately dismissed even before its end! I think though that the purpose of the notification is a gentle reminder and, lasting more than the typical 4-5 seconds goes against the norm and, it might annoy the user (or the user might think something is stuck, phone froze, etc..). Here is the code anyway:
UILocalNotification *howLongCanANotificationLast = [[UILocalNotification alloc]init];
howLongCanANotificationLast.alertBody=#"I am a notification";
howLongCanANotificationLast.soundName=#"musicfilename.mp3";
[[UIApplication sharedApplication] presentLocalNotificationNow:howLongCanANotificationLast];
Hope this helps.

Supress localNotification after an alertView is shown

In my app a distance, set by the user, is watched. When the distance is covered an AlertView dialog is shown and a sound is played. By tapping the OK butten the alertView dissapear and the sound stops. When the app moves to the background the method UILocalNotification takes care of the sound and the message. This works ok. But...
When the app is in the foreground and the AlertView is shown and dismissed, the UILocalNotification method stays active. Thus when the app moves to the background it "plays" the local notification with the sound (again).
How could I avoid that behavior?
I want the message played once. In the foreground OR in the background. Not both. I've tried to solve this problem with an if() statement but that gives me unexpected results.
Please advice.
Just call
[[UIApplication sharedApplication] cancelAllLocalNotifications];
when the user dismisses the alert in the foreground.
In case you need to have other local notifications active, just cancel the one in question.

UILocalNotification - Add 1 to CURRENT icon badge

So I've got a UILocalNotification setup to change the Icon badge.
[myNote setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1];
So it works fine if I don't change the badge number after I set it. If the badge shows 2, lets say, when I set the notification, it changes to 3 when the notification goes off. But lets say that I change it from 2 to 5 within the app before the notification fires, it still changes it to 3 when it does fire.
I need it to be able to add 1 to the current badge number, not the number that the badge showed when I first scheduled the notification. Ex: If it's 2 when I schedule the notification, then change it to 5 in the app, the notification should change it 6 when it does fire.
Is there a way to do it? I'm beginning to hate UILocalNotification.
Thanks guys!
Unfortunately, there is no such API. You can, however, discard all your previous notifications and reschedule them with the updated badge number. But I agree with you, local notifications and badge numbers are bound to reach a brick wall and annoy you.

How to make UILocalNotification which doesn't launch my app

I am using UILocalNotification to let a user know something. However, it's for a note for him and it doesn't require any actions in my application.
I set:
localNotification setAlertAction:nil];
[localNotification setHasAction: NO];
So, it shows only in the top of Home screen. However, if the user clicks on it, my app got launched.
Is there a way to create a local notification, which won't launch my app, when it's tapped?
If the user clicks on a local notification alert, iOS will launch the associated app. This is the expected behaviour of handling local notification. I don't believe you can change it.

Resources