nstimer

Run timer in 'background' when app is closed

喜你入骨 提交于 2019-12-17 13:27:19
问题 I need to run a timer in the background when my app is closed, however I have been reading that this isn't possible. I know that I can run it in the background for ~10 minutes, but I need considerably more than that (up to at least 2 hours). I was wondering if there is a way to do this by saving the timer value when the app is closed, the current time, retrieving them when it re-opens, and comparing them to the current time to get the difference. I could then restart the timer and add the

How can I make a countdown with NSTimer?

北城以北 提交于 2019-12-17 12:14:42
问题 How can I make a countdown with an NSTimer using Swift? 回答1: Question 1: @IBOutlet var countDownLabel: UILabel! var count = 10 override func viewDidLoad() { super.viewDidLoad() var timer = Timer.scheduledTimer(timeInterval: 0.4, target: self, selector: #selector(UIMenuController.update), userInfo: nil, repeats: true) } func update() { if(count > 0) { countDownLabel.text = String(count--) } } Question 2: You can do both. SpriteKit is the SDK you use for scene, motion, etc. Simple View

Passing parameters to the method called by a NSTimer

风格不统一 提交于 2019-12-17 10:18:39
问题 How can I pass a parameter to the method called by a NSTimer? My timer looks like this: [NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(updateBusLocation) userInfo:nil repeats:YES]; and I want to be able to pass a string to the method updateBusLocation. Also, where am supposed to define the method updateBusLocation? In the same .m file that I create the timer? EDIT: Actually I am still having problems. I am getting the error message: Terminating app due to uncaught

How do I make my App run an NSTimer in the background?

眉间皱痕 提交于 2019-12-17 07:15:15
问题 I'm making a benchmark App for test purposes ONLY. I am not intending this to go to the App Store. What I need is my NSTimer to continue running on the background using a UIBackgroundTaskIdentifier, save data to a Core Data db and finally push the data to a server (I'm using Parse), after a certain time interval, of course. So basically, I haven´t found any questions which apply to my specific case. I set my NSTimer like so: UIBackgroundTaskIdentifier bgTask; UIApplication *app =

swift NSTimer in Background

坚强是说给别人听的谎言 提交于 2019-12-17 05:14:50
问题 I have come across a lot of issues with how to handle NSTimer in background here on stack or somewhere else. I've tried one of all the options that actually made sense .. to stop the timer when the application goes to background with NSNotificationCenter.defaultCenter().addObserver(self, selector: "appDidEnterBackground", name: UIApplicationDidEnterBackgroundNotification, object: nil) and NSNotificationCenter.defaultCenter().addObserver(self, selector: "appDidBecomeActive", name:

Is NSTimer expected to fire when app is backgrounded?

不想你离开。 提交于 2019-12-17 05:08:11
问题 I don't understand it at all but NSTimer in my app definitely is running in background. I have a NSLog in method run by the timer and it is logging while it's in background. It's on iPhone 4 with iOS 4.2.1. I have declared location background support in Info.plist. I read the docs and many discussions here and elsewhere and it shouldn't be possible. Is it an iOS bug? Or undocumented feature? I don't want to use it and find out in near future, for example with coming of iOS 4.3 that Apple

Is NSTimer expected to fire when app is backgrounded?

 ̄綄美尐妖づ 提交于 2019-12-17 05:08:03
问题 I don't understand it at all but NSTimer in my app definitely is running in background. I have a NSLog in method run by the timer and it is logging while it's in background. It's on iPhone 4 with iOS 4.2.1. I have declared location background support in Info.plist. I read the docs and many discussions here and elsewhere and it shouldn't be possible. Is it an iOS bug? Or undocumented feature? I don't want to use it and find out in near future, for example with coming of iOS 4.3 that Apple

do runloops/multi-threading/timers behave differently on iOS6?

跟風遠走 提交于 2019-12-13 18:21:35
问题 I just installed Xcode 4.5 to start testing some code on iOS6 devices.. I wanted my existing code to be runnable on both iOS 5 and iOS 6 obviously. The same code (below) that used to work on Xcode 4.3 stopped working on Xcode 4.5: -(BOOL)readFromRingBuffer { NSDate *fireDate = [NSDate dateWithTimeIntervalSinceNow:0]; ringBufferReaderTimer = [[NSTimer alloc] initWithFireDate:fireDate interval:0.25 target:self selector:@selector(readRingBufferDataBit) userInfo:NULL repeats:YES]; NSRunLoop

Stop / Pause swift app for period of time

╄→гoц情女王★ 提交于 2019-12-13 12:27:21
问题 My app uses multiple threads of NSTimer Object. Within the one function (called randomly at random times, not a fixed delay) I want it to pause the whole app, pause the threads for 1 second only. I have the following code: [self performSelector:@selector(subscribe) withObject:self afterDelay:3.0 ]; Which is objective C, and I tried translating it into Swift like this: self.performSelector(Selector:changeColourOfPage(), withObject: self, afterDelay: 1.0) But I am getting the error Missing

How to add milliseconds to a stopwatch app?

徘徊边缘 提交于 2019-12-13 10:18:45
问题 Ok, so I've based my stopwatch app code from this tutorial right here http://iphonedev.tv/blog/2013/7/7/getting-started-part-3-adding-a-stopwatch-with-nstimer-and-our-first-class I like the way it is set up, but I can't figure out how to add hundredths of a second to it, anyone know how to do this? My ViewController.m file #import "ViewController.h" #import "Foundation/Foundation.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; } -