nstimer

Calling A Method At Specific Time Every Day

社会主义新天地 提交于 2019-11-26 21:25:53
问题 My app runs constantly in kiosk mode. Once every 24 hours at a specific time I need to sync some data from core data to a web service. I know how to do the sync piece but I don't know how to schedule the app to make the sync call at a specific time each day e.g. at 02:45 am. Is it possible to do something like this when an app is running constantly? 回答1: Use Local Notifications. Here is a tutorial:http://www.icodeblog.com/2010/07/29/iphone-programming-tutorial-local-notifications/ Hope this

How do I create a NSTimer on a background thread?

試著忘記壹切 提交于 2019-11-26 21:22:37
I have a task that needs to be performed every 1 second. Currently I have an NSTimer firing repeatedly every 1 sec. How do I have the timer fire in a background thread (non UI-thread)? I could have the NSTimer fire on the main thread then use NSBlockOperation to dispatch a background thread, but I'm wondering if there is a more efficient way of doing this. The timer would need to be installed into a run loop operating on an already-running background thread. That thread would have to continue to run the run loop to have the timer actually fire. And for that background thread to continue being

Swift how to use NSTimer background?

狂风中的少年 提交于 2019-11-26 20:44:58
问题 class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() var timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("update"), userInfo: nil, repeats: true) } func update() { println("Something cool") } } It's ok for the Simulator ,I will get continuous "Something cool" through I tapped the home button. But it worked out when I debug the app with my iPhone. I did't get anything when I tapped the home button and make my app run

Is NSTimer expected to fire when app is backgrounded?

老子叫甜甜 提交于 2019-11-26 20:37:35
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 silently "fixed" it and the app won't be working. Does anybody know more about it? NSTimer is going to fire

Sending Latitude and Longitude to Server when app is in background

半城伤御伤魂 提交于 2019-11-26 20:30:08
问题 I have gone through so many links, even after that I haven't found a proper solution for getting latitude and longitude. Periodic iOS background location updates iOS long-running background timer with "location" background mode I tried from some links and forums but it is working for only 3 mins, then app is not at all updating the user location. - (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate

How Do I write a Timer in Objective-C?

筅森魡賤 提交于 2019-11-26 19:47:10
I am trying to make a stop watch with NSTimer. I gave the following code: nst_Timer = [NSTimer scheduledTimerWithTimeInterval:0.001 target:self selector:@selector(showTime) userInfo:nil repeats:NO]; and it is not working in milliseconds. It takes more than 1 millisecond. Don't use NSTimer that way. NSTimer is normally used to fire a selector at some time interval. It isn't high precision and isn't suited to what you want to do. What you want is a High resolution timer class (using NSDate ): Output: Total time was: 0.002027 milliseconds Total time was: 0.000002 seconds Total time was: 0.000000

NSTimer not firing when NSMenu is open in Swift

别等时光非礼了梦想. 提交于 2019-11-26 17:48:45
问题 I have a timer that runs to restart an alarm once it goes off. alarm = NSTimer.scheduledTimerWithTimeInterval( 60 * minutesConstant + secondsConstant, target:self, selector: Selector("endSession"), userInfo: nil, repeats:false) Its selector function sets a mode flag, and calls the original function that set the alarm with new minutes and seconds constants, and also sends a user notification that the session has restarted. I have a menu item that gets updated with the remaining time So I've

Accuracy of NSTimer

为君一笑 提交于 2019-11-26 16:47:17
问题 I am trying to use NSTimer to create a Stop-watch style timer that increments every 0.1 seconds, but it seems to be running too fast sometimes .. This is how I've done it: Timer =[NSTimer scheduledTimerWithTimeInterval: 0.1 target:self selector:@selector(updateTimeLabel) userInfo:nil repeats: YES]; and then: -(void)updateTimeLabel { maxTime=maxTime+0.1; timerLabel.text =[NSString stringWithFormat:@"%.1f Seconds",maxTime]; } This will display the value of the timer in the Label, and I can

Press-and-hold button for “repeat fire”

感情迁移 提交于 2019-11-26 16:27:20
问题 I have referred to countless other questions about a press-and-hold button but there aren't many related to Swift. I have one function connected to a button using the touchUpInside event: @IBAction func singleFire(sender: AnyObject){ //code } ...and another function that is meant to call the function above repeatedly while the same button is held down, and stop when the button is no longer pressed: @IBAction func speedFire(sender: AnyObject){ button.addTarget(self, action: "buttonDown:",

iphone - NSTimers in background

感情迁移 提交于 2019-11-26 15:56:37
问题 Im developing an app that has to run in the background. It's a location based app, so it runs all the time, the OS doesn't kill it. It should send some info every 10 secs(just for debugging), I set a timer once its in the background. I set a breakpoint in the function that should be executed every 10 secs, which is never called, but if I pause the app and then continue the timer is called, and then the timer is executed every 10 secs without problems, weird right? I thought that the timer