I want to fire an alarm that will ring after 2 secs. How to handle alarm code.
Any help?
Thanks
You should look into the NSTimer class
It really depends what do you mean by an alarm...
If you want a popup alert after a while, you can use Local Notification, which is an iOS 4 feature. An example can be found here.
If you need certain function to be invoked by a timer, try NSTimer. Here is an example.
Related
I am creating an app where it will send you a local notification every 20 minutes. The problem I am having is once the app goes into background mode, the timer which triggers the function to run which executes some code then sends the user a notification won't run. Is there any alternative way of doing this? This timer runs on a loop, reseting its self every 20 minutes and running a function.
Thanks
Sure. Check out the documentation for UILocalNotification. You can set a fireDate to the exact second when you want the notification to go off. It also has parameters you can use to specify a repeat interval.
You cannot force the user to activate the app to run your function. Once the user taps the notification and your app becomes active, you can then perform all the logic you require (perhaps also including dealing with past "missed" notifications) .
I have an app in Xcode which handles sensitive data. I would like to terminate the app / exit forcefully if there is inactivity for 5 mins. Can someone please tell me how to do this?
Thank you!
Click here for a tutorial on how to make a timer. Every action that the user takes, reset the timer. When the 5 minutes are up, you can use exit(0).
However, this method of programatically closing your app is discouraged by Apple, so use it at your own discretion.
Edit: In order to stop the timer, you need to store a pointer to the timer that you create, and then call:
[pointerToTimer invalidate];
pointerToTimer = nil;
Edit 2: An alternative to using exit(0) would be to make a almost blank screen except for some text that states:
You have been inactive for too long. Please exit and restart this application.
Make this screen appear once the timer gets to 5 minutes. Therefore, the user can't do anything on the app but look at the screen, or exit the app.
If you're writing an app to submit to the app store, you can't (according to the guidelines). See details in this note: http://developer.apple.com/library/ios/ipad/#qa/qa1561/_index.html
If you don't care about the store or interface guidelines, it suggests that exit() is available.
Any tips on making five independent but simultaneous Countdown timers from 2 minutes down to 0, and then restarts at 2 min. And, whenever a user hits a reset button for each timer, that timer would reset to 2 min...
And, an alarm should sound when each timer reaches countdown below 10 sec..
Any help would be greatly appreciated!
:-)
Cheers,
loulou
How precise do you need your timers to be? If you can live with a tiny bit of uncertainly, go with NSTimers. Basically, you schedule 5 instances of NSTimer on your runloop. Each time through the loop, your app will check if a timer has fired, and perform some method if this is the case.
The nice thing about this approach is that you do not need to synchronize across multiple threads. You can schedule all of the timers on the main thread.
This is an embarrassing question but it involes Xcode and the iPhone SDK.
Why would I need to set more than one timer? And do 2 timers take up more 'tics' than 1 timer or are they all based on the same master internal clock?
Is it better to add 1 timer routine and just have it call all the things I need to make happen or have 5 or 6. I'm not new to programing but I'm completely new to xCode and just trying to wrap my head around it.
Eg. If I have a timer updating the clock on the screen, and I also want to update the GPS position, is there any reason not to have the same timer update both?
Thank you.
One is that timer delegate will operate in separate threads. So in your case, when only one timer is used, if the GPS acquisition takes to much time, your screen will feel unresponsive because the clock will be unregularly updated.
I have read the material regarding UILocalNotification , but there is no way i find to play a infinite loop sound when the notification is fired , it does play for a short time with showing an alert, but i want to achieve the goal of playing a continuos sound by providing the option of snooze and quite . I have gone through the UIEvent Kit too but unable to find a way to achieve this goal. One more question is there a way to customize the alert button action which are provided by default by the apple.
looking for you guys early response
Thanks in Advance.
I did not do that but there is a function when local notification fires this function is invoked but before it invoked the ok or view or what ever you name the button should be pressed after that you can sms code in that function and it should take care for that ...Hope This will help you