How to disable UILocalNotification in iPhone for some time? - iphone

I have implemented one reminder iphone applicaion in which I have used local notification for reminder.
In this application their one functionality alert on/off.
So when user set on then user get notification and if its off then user can get notification.
I have done googling but not got sucess.
Can you give me idea for that is it possible or not.
Thanks in advance

Do you have other notifications in your appln.
If you don't have other notification in your app than,
Do one thing,
When you set OFF
- cancel all the notification
- calculate the time difference of current time & your notification firing time. set this in to some variable.
when you set it ON
- reschedule your Notification based on the time which you have saved earlier.

I am considering that you know how UISwitch works, according to switch position
UILocalNotification *localNotif;
//if switch is on
localNotif = [[UILocalNotification alloc] init];
//else if localNotif is not equal to null then
localNotif = nil;
You can start a timer which continuously check switch position and do the above stuff that depends on your coding.

Related

Show AlertView dialog from UILocalNotification

In my app there should be an alarm when a certain distance is covered. Originally, when the conditions are met, I wanted to move the app to the foreground, show an AlertView and play a sound. Due to answers to my former post I've implemented UILOcaLnotifications and it works fine for playing an AlertSound. Even when my app is in the background and thats great. One issue remains unsolved at this moment. I really want to popup a dialog (AlertView) when the conditions are met.
At this moment the ALert message is shown at the top of the screen (like a received message or missed call) but I want to present the user with a dialog (like in the clock app)
Does anyone knows a solution to this question? Help is most appreciated.
Did you try to assign alertBody and alertAction?
notification.alertBody = #"Some message";
notification.alertAction = #"View"; //title of action button
notification.hasAction = YES; //it YES by default

Local Notification Alert Timing

notificaiton = [[UILocalNotification alloc] init];
notificaiton.fireDate = [NSDate Date];
notificaiton.repeatInterval = 0;
notificaiton.alertBody = #"Alarm";
notificaiton.timeZone = [NSTimeZone defaultTimeZone];
notificaiton.repeatCalendar = [NSCalendar currentCalendar
notificaiton.soundName = #"Alarm.wav"
[[UIApplication sharedApplication] scheduleLocalNotification:notificaiton];
my question is ,
Local Notification alert stay only for few seconds but, is it possible, local notification alert stay for few minutes?
please any body has answer
Thanks, In Advance
No it is not possible to customize the AlertView and its timings. System does it and we don't have any control over it. We can only customize, the alertbody and title of the action button.
Configure the substance of the notification: alert, icon badge number, and sound.
The alert has a property for the message (the alertBody property) and
for the title of the action button or slider (alertAction); both of
these string values can be internationalized for the user’s current
language preference.
if you mean that you need to play notification sound more than 30 sec ??? then it is not possible.
you wrote that Local Notification alert stay only for few seconds but check proper that, this stay as per your sound file length.
and this sound file Must be maximum 30 sec in length.
if you will try to give soundName more than 30 sec. then it will play default sound in notification.
find this line
"Sounds that last longer than 30 seconds are not supported. If you specify a file with a sound that plays over 30 seconds, the default sound is played instead." into apple notification doc.

Remove LocalNotification Badge Number from launcher icon

I am trying to add a feature in app in which whenever i made a note, it will Call a UILocalNotification after few days (Hardcoded). Now, on launcher Icons i can see a red badge with marker "1". How can I remove this badge?
Best Regards
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
Add that line in whatever code handles the user's interaction with the local notification. If you want the badge to be cleared when the local notification fires, you can't (because setting the notification's applicationIconBadgeNumber property to 0 would simply mean "don't change the existing badge.")

Schedule a local notification on firing a local notification

I want to schedule a local notification when my previous local notification gets fired.
It should get scheduled disregarding the user taps 'View' or 'Cancel'.I am not getting proper place(delegate method)to schedule a new notification.According to Apple docs,application:(UIApplication *)application didFinishLaunchingWithOptions: can be used but it doesn't seems to be get called when application comes to foreground from background and application:(UIApplication *)application didReceiveLocalNotification: gets called only on click of 'View' and not on close.How should I do this?Any help is highly appreciated.
Yes. You are correct about the local notifications. You should click "view" to get the didReceiveLocalNotification: triggered. If you click "Cancel", you are not caring about the notificaiton. If you don't care, why should the iOS care? :-)
You are scheduling the notification. So, you know when it will be fired. Don't you? Then why wait for the first notification to be fired? Just schedule the second notification along with the first notification.
A workaround:
Local and Push Notification Programming Guide
says that only 64 local notifications are allowed per app. So, schedule the first 64 notifications initially. And when the app opens the next time, check [UIApplication sharedApplication] scheduledLocalNotifications], and schedule the next (64 - scheduledLocalNotifications) notifications.
int scheduledNotifications = [UIApplication sharedApplication] scheduledLocalNotifications];
int n = 64 - scheduledNotifications;
[self Schedule-next-n-notifications];
Note: We can't guarantee that this will work perfectly. In case, if the app opens after very long gap, for example after 1 or 2 months, some notifications would have not been scheduled at the proper time.

How to show a UILocalNotification when ASINetworkQueue finishes all requests?

I'm using ASIHTTPRequest to download multiple files while the iPhone app is running in the background. I want to present a UILocalNotification when the queue finishes.
The following delegate method isn't called until the app is resumed:
- (void)queueFinished:(ASINetworkQueue *)aQueue
{
NSLog(#"Queue finished");
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = NSLocalizedString(#"All downloads completed");
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
[localNotification release];
}
}
So, how can I make this notification appear?
The reason your delegate isn't getting called is likely because your app is suspended in the background. If you are doing some sort of lengthy network process that continues after the user closes the app, you can use -[UIApplication beginBackgroundTaskWithExpirationHandler:] when you start the network tasks so that your application continues running in the background until you're done with the network tasks. However, it can still expire so you're not guaranteed to get enough time to finish.
From previous SO question notification when program is in background iOS 4
You do realize that when your app is in a suspended state, you won't receive any notifications -- and this is right in the documentation. There are only 3 classes of applications that can receive notifications: Audio applications (like iPod and analogues), location based applications, and voip apps. Your plist has to be set up correctly if your app is one of those applications.
Use this:
UILocalNotification *localNot = [[UILocalNotification alloc] init];
localNot.alertBody = #"Your Text";
localNot.alertAction = #"Name on the button";
localNot.fireDate = [NSDate date];
localNot.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:localNot];
What you're doing:
Create the LocalNotification
Add the body of your LN
Add the name of the button which appears on the "alert"
Set the fireDate to the actual date and time (maybe you need to increase the actual date with 1 or 2 seconds - for this use: dateByAddingTimeInterval:)
Set the soundName (you could also use a custom sound...)
Schedule / Create the LN
Do you have your queue maxConcurrentOperationCount set to 1?
The method setShouldContinueWhenAppEntersBackground:YES is set on a per request basis, and since you have a bunch of ASIHTTPRequest's inside a queue, only one of them may be executing at a time. This means that the other items in your queue haven't even started when you suspend the app, so the OS doesn't know yet to keep that network request alive.
I'm not sure of a solution, but I think this is the reason for what you're seeing.