nstimer

How to run timer thought the app entered background or is terminated

邮差的信 提交于 2019-11-27 08:45:16
问题 In my app I have a NSTimer, and a selector - (void)TimerCount . I also have a integer int CountNum , and every 0.01 second, it increases by 1 ( CountNum = CountNum + 1 ). Timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(TimerCount) userInfo:nil repeats:YES]; And I want the timer to resume thought the app is terminated or it entered background. How can I do this? 回答1: If your application is terminated , you will not be able to continue processing. To operate

Format realtime stopwatch timer to the hundredth using Swift

懵懂的女人 提交于 2019-11-27 07:57:54
问题 I have an app using an NSTimer at centisecond (0.01 second) update intervals to display a running stopwatch in String Format as 00:00.00 (mm:ss.SS). (Basically cloning the iOS built-in stopwatch to integrate into realtime sports timing math problems, possibly needing millisecond accuracy in the future) I use (misuse?) the NSTimer to force-update the UILabel. If the user presses Start, this is the NSTimer code used to start repeating the function: displayOnlyTimer = NSTimer

How can I make a countdown timer like in a music player?

若如初见. 提交于 2019-11-27 07:33:00
问题 I have a label and its value is "03:48". I want to countdown it like a music player. How can I do that? 03:48 03:47 03:46 03:45 ... 00:00 var musictime =3:48 func stringFromTimeInterval(interval: NSTimeInterval) -> String { let interval = Int(interval) let seconds = interval % 60 let minutes = (interval / 60) return String(format: "%02d:%02d", minutes, seconds) } func startTimer() { var duration=musictime.componentsSeparatedByString(":") //split 3 and 48 var count = duration[0].toInt()! * 60

How to detect a pause in input for UISearchBar/UITextField?

时光总嘲笑我的痴心妄想 提交于 2019-11-27 07:19:27
I have the following UISearchbar code: - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; NSString* endpoint =[NSString stringWithFormat:@"http://www.someurl/", [searchText stringByReplacingOccurrencesOfString:@" " withString:@"+"]]; NSURL* url = [NSURL URLWithString:endpoint]; NSURLRequest* request = [NSURLRequest requestWithURL:url]; GTMHTTPFetcher* myFetcher = [GTMHTTPFetcher fetcherWithRequest:request]; [myFetcher beginFetchWithDelegate:self didFinishSelector:@selector

calling a method after each 60 seconds in iPhone

元气小坏坏 提交于 2019-11-27 05:32:29
问题 I have created an GKSession and as its object is created, it starts search for availability of devices, as - (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state { I want to call this method after each 60 seconds, what should I do? 回答1: Use NSTimer NSTimer* myTimer = [NSTimer scheduledTimerWithTimeInterval: 60.0 target: self selector: @selector(callAfterSixtySecond:) userInfo: nil repeats: YES]; After each 60.0 second , iOS will call the below

Add a running countup display timer to an iOS app, like the Clock stopwatch?

蓝咒 提交于 2019-11-27 04:25:49
I'm working with an app that processes device motion events and updates interface in 5 second increments. I would like to add an indicator to the app that would display the total time the app has been running. It seems that a stopwatch-like counter, like the native iOS Clock app is a reasonable way to count time that the app has been running and display it to the user. What I'm not sure of is the technical implementation of such a stopwatch. Here's what I'm thinking: if I know how long between interface updates, I can add up seconds between events and keep a count of seconds as a local

Xcode 7.3 / Swift 2: “No method declared with Objective-C selector” warning

瘦欲@ 提交于 2019-11-27 04:24:26
问题 I've been using selectors for a while, and even after migrating to Swift I was able to use them without issues. That's how I was using on Swift 2 without issues until I updated Xcode to version 7.3: As use can see I use selectors with NSTimer. This is the action that is called: func Start () { } As you can see Xcode 7.3 now gives a warning "No method declared with Objective-C selector". By clicking on the warning, Xcode offers a quick fix to the code by adding "Selector", but then I still get

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

久未见 提交于 2019-11-27 03:36:28
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 = [UIApplication sharedApplication]; bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ [app endBackgroundTask

Objective-C : NSTimer and countdown

半世苍凉 提交于 2019-11-27 02:58:12
问题 I know that I should understand Apple's documentation for NSTimer, but I don't! I have also read a lot of questions about it but can not find one that suites my case. Well here it is: The user enter hour and minutes through textfields. I convert those to integers and display them in a "countDownLabel". How can i make the count down to zero? It would be nice to show the seconds which is something that the user didn't imported but i guess it will not be hard to show. How could somebody stop

NSTimer Reliable Alternatives

孤街醉人 提交于 2019-11-27 02:49:24
问题 I have an application that is supposed to log certain things every 1 second and I'm currently using NSTimer , but if my application transitions screens (or almost anything else, really) it slows down the timer a little bit making for inaccurate readings. What is a reliable alternative to use? My current code is as follows: timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(update) userInfo:nil repeats:YES]; 回答1: NSTimer is not guaranteed to fire exactly on time