nstimer

iOS5 ARC is it safe to schedule NSTimers from background selectors?

China☆狼群 提交于 2019-12-06 06:06:23
问题 I'm trying to debug my application. I've been using some NSTimer instances in my non-arc code like this (from the main thread): [NSTimer scheduledTimerWithTimeInterval:5 target:musicPlayer selector:@selector(playPause:) userInfo:nil repeats:NO]; This works fine if I assign this code to a button and click a button. The timer fires. I've also tried: if( self.deliveryTimer == nil) { self.deliveryTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(playPause:)

iOS 5 deep sleep prevention

不问归期 提交于 2019-12-06 03:40:23
问题 I'm trying to build an alarm app that can fire an alarm while in locked-screen mode (the app is in the foreground, but the screen is locked). The alarm has to be triggered by a NSTimer not by uilocalnotification. In iOS 4 I used the 'play silent sound every 10 seconds' hack to prevent the app from going to deep sleep and the timer events worked fine. However, in iOS 5 this doesn't seem to work. Any ideas? Or this should work and I'm doing something wrong? 回答1: It seems that you actually can

OS X Cocoa timer not fired when application on background

坚强是说给别人听的谎言 提交于 2019-12-06 02:32:52
A third-party library provides a function I need to call every 100ms. Setting up a timer to do that works very well as long as my app is on foreground. When my app is on background timer works for a while but after a about a minute timer is called only after 10 second delay. The same happened when I created a separate thread with usleep-function. Is there any way I can keep timer running while my app is on background? Use beginActivityWithOptions:reason: to disable app nap for your application. You should try and re-architect to avoid these sorts of frequent timers, especially when your

NSTimer behavior in background (addTimer:, beginBackgroundTaskWithExpirationHandler:)

六眼飞鱼酱① 提交于 2019-12-06 01:33:58
Xcode 6.3.1 ARC Enabled, for iOS 8.3 I need help understanding a strange behavior that I encounter while trying to maintain a singleton shared timer in my application after it enters background. Previously I did not care for this NSTimer as it was updated with user location in the background using background location services. However, I would like to address the case where the user rejects location updates while in background or location updates all together. The location and the timer go hand in hand for my app. I worked through quite a bit of information in the following threads and website

Running NSTimer on a thread

谁说我不能喝 提交于 2019-12-06 00:46:12
I am trying to run a NSTimer on a thread using iPhone SDK 3.0. I think I am doing everything correctly (new runloop etc.). If I call [timer invalidate] on viewDidDissappear though I get this error: bool _WebTryThreadLock(bool), 0x3986d60: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now... Program received signal: “EXC_BAD_ACCESS”. Here is my code: - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [activityIndicator startAnimating]; NSThread* timerThread =

NSTimer Decrease the time by seconds/milliseconds

房东的猫 提交于 2019-12-06 00:19:59
问题 I am developing a QuiZ app. It needs a countdown timer, In that I want to start a timer at 75:00.00 (mm:ss.SS) and decrease it to 00:00.00 (mm:ss.SS) by reducing 1 millisecond. I want to display an alert that Time UP! when time reaches to 00:00.00 (mm:ss.SS). I am displaying the time by following below link Stopwatch using NSTimer incorrectly includes paused time in display 回答1: Here is a simple solutions to your problem. Declarations @interface ViewController : UIViewController { IBOutlet

Disable a Button for 90 sec when pressed in swift

蓝咒 提交于 2019-12-05 18:49:31
I have button that show up a modal view but i want that if the user click it he wont be able to use it again for 90 seconds. how can i do this? In the IBAction of the button disable the button and set a timer like this: self.button.enabled = false NSTimer.scheduledTimerWithTimeInterval(90, target: self, selector: "enableButton", userInfo: nil, repeats: false) And create the func called when the timer ends counting: func enableButton() { self.button.enabled = true } #Swift 3 Write this code where you want to disable button. self.buttonTest.isEnabled = false Timer.scheduledTimer(timeInterval: 90

Display StopWatch Timer animated like the petrol pump meter using NSTimer

对着背影说爱祢 提交于 2019-12-05 18:32:43
I am new in iOS developement.When I press the stopwatch start button I want to display the timer like counter token effect.I have attached image for your reference.I have done to display secs and minutes but I dont know, How animate autoscroll effect? How can I do this? When the counter is moving it shouldn't jump from one number to another number, instead it should move from one number to next number smoothly, just like the petrol pump meter. Thanks You need to manually scroll tableView instead of scrollToRowAtIndexPath because this animation uses its own timer interval and its very difficult

scheduledTimerWithTimeInterval vs performselector with delay with iOS 5.0

纵饮孤独 提交于 2019-12-05 18:15:55
问题 i am doing function call with scheduledTimerWithTimeInterval. i am just checking that xml parsing is completed or not for particular web services and invalidating timer in didEndElement method after getting successful response. timerForStopWebService = [NSTimer scheduledTimerWithTimeInterval:30.0 target:self selector:@selector(stopWS) userInfo:nil repeats:NO]; now i am facing problem with iOS 5.0 and its working fine in other iOS versions. in iOS 5.0, a function stopWS call anytime even if i

Having trouble with NSTimer (Swift)

半腔热情 提交于 2019-12-05 17:44:19
问题 --EDITED WITH UPDATED INFORMATION-- What I wish to do is call a function named timerFunc once every five seconds using a NSTimer.scheduledTimerWithTimeInterval method, the issue seems is that during runtime, I get the error Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [Animation.ViewController timerFunc:]: unrecognized selector sent to instance 0x7fe548d66040' In the output log. I've been looking up other people's NSTimers to no avail, I see quite a few