ActionIndicatorView hidden after a some time - iphone

i want to hidden ActionIndicatorView after a 7 seconde for exemple

Use timer to do this functionalty
[NSTimer timerWithTimeInterval:7 target:self selector:#selector(viewhidefunction) userInfo:nil repeats:NO];
In function make yourview.hidden=TRUE;

Related

app freezes, not device hang. In game using cocos2d

I'm using XCode 5. I'm making a game using Cocos2D. And want some functions to do repeatedly in sequence and one after another. Due to many actions performed at a time, so wants a delay too (by which no action is interfered by the next one and not cancelling the effect of previous one or rescheduling and perform the function immediately).
My interface freezes and in Debug Navigator, CPU consumption reaches between 99-100% and memory gradually increasing and remain increasing. I put all exceptions breakpoint, too. But no exception arises.
I'm using this code
-(void)threadMainRunLoop
{
BOOL exitNow = NO;
int loopCount = 1;
[self function1];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
// Add the exitNow BOOL to the thread dictionary.
NSMutableDictionary *threadDict = [[NSThread currentThread] threadDictionary];
[threadDict setValue:[NSNumber numberWithBool:exitNow] forKey:#"ThreadShouldExitNow"];
// Install an input source.
[NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:#selector(function2) userInfo:nil repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:0.4 target:self selector:#selector(function3) userInfo:nil repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:0.4 target:self selector:#selector(function4) userInfo:nil repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:#selector(function5) userInfo:nil repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:1.2 target:self selector:#selector(function6) userInfo:nil repeats:NO];
while (loopCount <= 4 && !exitNow)
{
// Do one chunk of a larger body of work here.
// Change the value of the moreWorkToDo Boolean when done.
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:#selector(function2) userInfo:nil repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:0.4 target:self selector:#selector(function3) userInfo:nil repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:0.4 target:self selector:#selector(function4) userInfo:nil repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:0.7 target:self selector:#selector(function5) userInfo:nil repeats:NO];
[NSTimer scheduledTimerWithTimeInterval:1.2 target:self selector:#selector(function6) userInfo:nil repeats:NO];
// Run the run loop but timeout immediately if the input source isn't waiting to fire.
[runLoop runUntilDate:[NSDate dateWithTimeInterval:5.0 sinceDate:[NSDate date]] ];
// Check to see if an input source handler changed the exitNow value.
exitNow = [[threadDict valueForKey:#"ThreadShouldExitNow"] boolValue];
++loopCount;
}
}
And calling this function in ccTouchesEnded:withEvent:.
I followed this code from Thread Management of "Listing 2-3 Checking for an exit condition during a long job".
Is my NSRunLoop make my game/interface to freeze???
Remember device in not hanged. And function1-6 are updating UI. And also when the game will freeze is not expected, may be after some time or after a long time or even may not freeze.
Thanks in advance.
cocos2d is not thread-safe, so if any of these scheduled functions perform cocos2d actions or modify nodes on a background thread there will be problems. Instead use cocos2d's builtin scheduleSelector:interval: methods.
A specific issue here is the while loop. You call runUntilDate which blocks the main thread for 5 seconds, and you do that up to 4 times. Which means cocos2d and ui get to update and draw their state once every 20 seconds. No wonder the app freezes.
If you want to do some multithreading, use performSelectorInBackground or grand central dispatch. Run loops and threads are too low level if you don't control the app's entire run loop and all threads.

NSTimer how to disable while timer is still active?

I have created a timer,
self.scanTimer = [NSTimer scheduledTimerWithTimeInterval:TIMEOUT_SECONDS target:self selector:#selector(meInterrupted:) userInfo:nil repeats:NO];
and some point in time in my code, i feel to disable it before timeout happens, so that the meInterrupted not to be called?. How to achieve this ?
Just call [self.scanTimer invalidate]; This will keep the timer from ever firing if it is called before the timer fires.

NSTimer not running

I've got a program in which I want to code a timer which checks wether the user is idle or not. For that I wrote following code:
if (!idleTimer) {
NSLog(#"make");
idleTimer=[[NSTimer alloc]initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:10.0]interval:10 target:self selector:#selector(idleTimerExceeded) userInfo:nil repeats:NO];
NSLog(#"madetimer with: %f, %#", idleTimer.timeInterval, idleTimer.fireDate);
}else {
NSLog(#"no reset timer: %f", idleTimer.timeInterval);
if (fabs([idleTimer.fireDate timeIntervalSinceNow]) < 9) {
NSLog(#"reset");
[idleTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:10]];
}
}
But somehow my logs show that the interval is always 0.0000 . Which means that something is wrong here. Can anybody help me?
ive never seen a timer look so complicated. try this:
write a method that checks if the user is idle (lets say idleChecker)
then make the timer repeatable and calls that method idleChecker
[NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:#selector(idleChecker) userInfo:nil repeats:YES];
remember to declare the idleChecker method in the .h file
take note if u want to stop the timer event then you need to maintain a reference to it
NSTimer aTimer = [NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:#selector(idleChecker) userInfo:nil repeats:YES];
then to stop it
[aTimer invalidate];
as for checking if its running i would just stick a nslog message in there stating something like "check for idle user"

is there timer in ios

I want to create a timer for example to count 2 sec and after each second an nslog type for example 1 sec passed
any suggestion to do that
yes there is NSTimer, use it as -
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector() userInfo:nil repeats:NO];
What you're after is NSTimer.
Which, I can't not point out, even a cursory search of the framework docs would have turned up. Laziness IS one of the three Virtues of the Programmer, but c'mon.
You can call your NSTimer like this
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector(changeValue) userInfo:nil repeats:YES];
changeValue function can be like
-(void)changeValue{
NSLog("calling function after every two seconds");
}
You might want to use NSTimers timerWithTimeInterval:target:selector:userInfo:repeats:
method. Point that towards some object that implements a selector which prints your log entries.
Yes, ios having timer which is used for periodically call method or button touchup event. we can use it like following:
[NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:#selector(Your_target_Method)
userInfo:nil
repeats:NO];
NSInteger timer=0;
now call method every 1 sec
-(void)Your_target_Method{
timer=timer+1;
NSLog(#"Timer:%ld",timer);
}
Furthermore, visit https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Timers/Timers.html

I want to call a method after particular time until my app opened in iphone?

I want to call a method after each 2 minutes,
how can I apply such logic?
Use an NSTimer object. It's been talked about quite a lot here, so I won't repeat all that - just search for "NSTimer" in the search box at the top right. :-)
You can use a timer..
[NSTimer scheduledTimerWithTimeInterval:120.0 target:self selector:#selector(yourFunction:) userInfo:nil repeats:YES];
.........
..........
-(void)yourFunction:(NSTimer*)timer{
//do your action here
}
I use a NSTimer to trigger a method. I use the below code in my initial viewDidLoad section:
myTimer = [NSTimer scheduledTimerWithTimeInterval:120.0 target:self selector:#selector(theMethod) userInfo:nil repeats:YES];
Hope that helps.