nstimer

swift NSTimer in Background

左心房为你撑大大i 提交于 2019-11-27 02:23: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: UIApplicationWillEnterForegroundNotification, object: nil) At first I thought that my problem is solved, I just

Passing parameters to a method called by NSTimer in Swift

不羁的心 提交于 2019-11-27 02:14:08
I'm trying to pass an argument to a method that is called by NSTimer in my code. It is throwing an exception. This is how I'm doing it. Circle is my custom class. var circle = Circle() var timer = NSTimer.scheduledTimerWithInterval(1.0, target: self, selector: animate, userInfo: circle, repeats: true) Below is the method that is being called func animate(circle: Circle) -> Void{ //do stuff with circle } Note: The method is in the same class that it is being called. So I believe i've set the target correctly. Andy The selector you use with NSTimer is passed the NSTimer object as it's one and

How to run NSTimer in background beyond 180sec in iOS 7?

痴心易碎 提交于 2019-11-27 01:59:44
I have tried this but not working more than 180 sec in iOS 7 and Xcode 4.6.2. Please help me UIBackgroundTaskIdentifier bgTask = UIBackgroundTaskInvalid; UIApplication *app = [UIApplication sharedApplication]; bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ [app endBackgroundTask:bgTask]; }]; NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:20 target:self selector:@selector(timerMethod) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; -(void) timerMethod{ NSLog(@"in timerMethod"); } null Unless you enable one of the

make timer run on background iOS for more than 3 minutes

泄露秘密 提交于 2019-11-26 23:35:16
问题 So I need this app to run timer for more than 3 minutes, and play a sound like very 45 seconds, most of the solutions here are just for less than 3 minutes on iOS. Is there a way to make it run all the time, unless the app stops? After the research, I guess the solution is implement beginBackgroundTaskWithExpirationHandler and stops it by giving a handler and set location update on plist ? As for audio, besides setting the plist, anything else need to do to play audio? Swift how to use

Stopwatch using NSTimer incorrectly includes paused time in display

五迷三道 提交于 2019-11-26 23:18:02
问题 This is my code for an iPhone stopwatch. It works as expected and stops and resumes when the buttons are clicked. When I hit "Stop", however, the timer won't stop running in the background, and when I hit "Start" to resume it, it will update the time and skip to where it is currently instead of resuming from the stopped time. How can I stop the NSTimer ? What is causing this to occur? @implementation FirstViewController; @synthesize stopWatchLabel; NSDate *startDate; NSTimer *stopWatchTimer;

Dynamically Updating a UILabel

夙愿已清 提交于 2019-11-26 23:08:06
I have a question regarding UILabels. I'm not even sure it is the right way to pull this off but I am trying to update a UILabel to display two numbers from 0 to 24 then loop back to zero and display the numer squence again. The catch is, it needs to update the UILabel every 1/24 of a second. Here is the code I have so far... -(void)viewDidLoad { fpsTimer = [NSTimer scheduledTimerWithTimeInterval: .01 target: self selector: @selector(updateFpsDisplay) userInfo: nil repeats: YES]; } - (void)updateFpsDisplay { for (int i=0; i<100; i++) { NSLog(@"%d", i%24); [timecodeFrameLabel setText:[NSString

NSTimer timerWithTimeInterval: not working

我的未来我决定 提交于 2019-11-26 22:49:33
I've created a test application with timer before implementing it in my project. It was the first time I'm using timer. But the issue is when I implemented timer using [NSTimer timerWithTimeInterval: target: selector: userInfo: repeats: ]; , it is not working. Here is my code, Interface: @interface uialertViewController : UIViewController { NSTimer *timer; } -(void)displayAlert; -(void)hideandview; @end Implementation: @implementation uialertViewController - (void)viewDidLoad { [self displayAlert]; [super viewDidLoad]; } -(void)displayAlert{ timer = [NSTimer timerWithTimeInterval:1 target:self

NSTimer not fired when uiscrollview event occurs

為{幸葍}努か 提交于 2019-11-26 22:16:44
问题 I have a UIImageView placed in UIScrollView, Basicly this UIImageView holds very big map, and created animation on a predefined path with "arrows" pointed navigation direction. But, whenever uiscrollevents occurs, I think MainLoop freezes and NSTimer being not fired, and animation stopped. Are there any existing property, which solves this problem, on UIScrollView, CAKeyFrameAnimation or NSTimer? //viewDidLoad self.myTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:

Repeating NSTimer, weak reference, owning reference or iVar?

心不动则不痛 提交于 2019-11-26 21:35:14
问题 I thought I would put this out here as a separate question from my previous retaining-repeating-nstimer-for-later-access as the discussion has moved forward making a new question clearer than yet another EDIT: The scenario is an object creates a repeating NSTimer, lets say in viewDidLoad, once created the NSTimer needs to stay around so it can be accessed by other methods. NSTimer *ti = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateDisplay:) userInfo:nil

how to pause and resume NSTimer in iphone

徘徊边缘 提交于 2019-11-26 21:33:15
问题 hello I am developing small gameApp. I need to pause the timer,when user goes to another view [say settings view]. when user comes back to that view , I need to resume the timer. can anybody solve this issue ... Thanks in Advance... 回答1: You can't pause a timer. However, when the user goes to the settings view, you can save the fireDate of the timer and also the current date. After this you invalidate the timer and let the user do his/her stuff. Once he/she switches back to the game, you