nstimer

Wake app at regular intervals while using UIBackgroundModes=location

ⅰ亾dé卋堺 提交于 2019-12-12 03:22:52
问题 I'm developing a navigation app which uses the UIBackgroundModes=location setting and receives CLLocationManager updates via didUpdateToLocation . That works fine. The problem is that the intervals between location updates are very hard to predict and I need to make sure the app is called something like once every few seconds to do some other (tiny) amounts of work even if the location did not change significantly. Can I do that? Am I allowed to do that? And how can I do that? I found a blog

Timer decrement gets varied for each page load when using back button

霸气de小男生 提交于 2019-12-12 03:06:16
问题 In my previous question Timer decrement gets varied for each page load I got the code working well when I used "Invalidate" and "Release". But when i use a back button the same problem repeats. And i need a stop option too.. -(IBAction)back:(id)sender { [self dismissModalViewControllerAnimated:YES]; } -(IBAction)stop:(id)sender { [theTimer invalidate]; [theTimer release]; } this is the code i used here but not working well. 回答1: Try using it in this way.. if ([theTimer isValid]) { [theTimer

Call a function once per second for 10 seconds

放肆的年华 提交于 2019-12-12 01:56:23
问题 I need to know how you can perform an operation for total time, I'll explain, I need to repeat my call to a function for 10 seconds and then just every 1, I tried using a timer, but I understand what's called function EVERY 10sec and not FOR 10 sec. Does anyone have any ideas? thanks 回答1: I'm guessing you mean that you want to call a function once per second, and stop calling it after ten seconds. And I suspect that you will want to be able to change the interval (once per second) and the

OSX Core MIDI- Calling MIDIPacketListAdd from NSTimer

岁酱吖の 提交于 2019-12-12 01:52:20
问题 I'm sending a string of MIDI packets using MIDIPacketListAdd. I want to change the packets dynamically during playback, so I'm using a NSTimer to add each packet before the scheduled time the packet should go out. The code works perfectly, the address of the current packet is updated correctly, I have verified that all the data is correct. However, no MIDI data is being sent when MIDIPacketListAdd is called from the timer. I add the first two packets before starting the timer to make sure

Application did enter background function

风格不统一 提交于 2019-12-12 01:34:55
问题 Hey I got a pretty low interval timer in my firstViewController which I would like to terminate when the app enters background, but how am I supposed to access it from my Applications AppDelegate file where the function is located. I know this is extremely dumb question, but I would appreciate help. Thanks! 回答1: In your firstViewController, you would listen for UIApplicationDidEnterBackgroundNotification. In the firstViewController init method: - (void)addObserver:(id)notificationObserver

Accelerometer must be in a specific orientation for a given time interval before next action

不羁的心 提交于 2019-12-12 00:42:02
问题 I am trying to execute a method in my application, but only after the phone was been in the correct accelerometer orientation for a given time interval. The problem I am having is each time the accelerometer is updated, the timer resets. I have not been able to figure out how to trigger the time to start only once and not each time the accelerometer is updated. // In ViewController.h #import <UIKit/UIKit.h> #import <CoreMotion/CoreMotion.h> @interface ViewController : UIViewController { float

Objective c : How to set time and progress of uiprogressview dynamically?

大城市里の小女人 提交于 2019-12-12 00:29:19
问题 Say I have a UIProgressBar with size (394,129,328,9) and I increased the height with CGAffineTransform transform = CGAffineTransformMakeScale(1.0f, 3.0f); PgView.transform = transform; What I need to implement is : If I have 5 minute time,the progressView should be filled with a certain amount and totally filled at the end of 5 minute. Same for 1 minute and 30 minutes too. I am implementing like this : -(void)viewWillAppear:(BOOL)animated { CGAffineTransform transform =

Check UIImageView array frame equality with NSTimer

大憨熊 提交于 2019-12-11 23:46:44
问题 I am wondering how to check if all the frames of two UIImageView NSMutableArray s are equal to each other. Now I am using a NSTimer for that. Here is the code which I used in the method: __block BOOL equal = YES; [Img1Array enumerateObjectsUsingBlock:^(UIImageView *ImageView1, NSUInteger idx, BOOL *stop) { UIImageView *ImageView2 = Img2Array[idx]; if (!CGRectEqualToRect(ImageView1.frame, ImageView2.frame)) { *stop = YES; equal = NO; } }]; if (equal) { NSLog(@"ALL THE FRAMES ARE EQUAL");

How do I run a function with a parameter every 5 seconds in Swift?

三世轮回 提交于 2019-12-11 23:21:25
问题 I want to execute the following function every 5 seconds. I have seen the other answers to related questions that say to use NSTimer.scheduledTimerWithTimeInterval but that only works for functions without any arguments. The function: func sayHello(name: String) { println("Hey \(name)!") } This is the code I tried: var timer = NSTimer.scheduledTimerWithTimeInterval(5.0, target: self, selector: Selector("sayHello(\(name))"), userInfo: nil, repeats: true) But it crashes the app with the error:

NSTimer, Threads. How to create a threaded NSTimer?

邮差的信 提交于 2019-12-11 23:09:22
问题 I'm developing a UIView where there must be a process that accesses to remote database and must update a UITableView with the retrieved results. To do that I'm planning use a NSTimer that runs each 10 seconds the update process where database is accessed and data retrieved. The problem is that if I run this in the main thread the view will be frozen till the data is retrieved and loaded. Anyone knows wicht is the best way to do that? Any example will be apreciated. Thanks. EDIT ---- This is