jjzjj

ios - 一段时间后 NSTimer 在后台停止触发

嘿,我正在开发一个应用程序,我必须在其中每30秒调用一次API,所以我为它创建了NSTimer。但是当我的应用程序进入后台时,计时器会在3-4分钟后停止触发。所以它在后台只工作3-4分钟,但之后就不行了。我怎样才能修改我的代码,使计时器不会停止。这是我的一些代码。-(IBAction)didTapStart:(id)sender{NSLog(@"heyiminthetimer..%@",[NSDatedate]);[objTimerinvalidate];objTimer=nil;UIBackgroundTaskIdentifierbgTask=UIBackgroundTaskInva

iOS NSTimer 不工作?

这个问题在这里已经有了答案:NSTimertimerWithTimeInterval:notworking(4个答案)关闭7年前。这是我的确切代码,它似乎不起作用。你能告诉我我做错了什么吗?请注意,refreshTimer已在私有(private)接口(interface)中声明。-(void)viewDidLoad{refreshTimer=[NSTimertimerWithTimeInterval:1target:selfselector:@selector(timerTest)userInfo:nilrepeats:YES];}-(void)timerTest{NSLog(@"T

ios - NSTimer 不会将参数传递给选择器

我创建了一个NSTimer:[NSTimerscheduledTimerWithTimeInterval:2.0target:selfselector:@selector(createObject:)userInfo:nilrepeats:YES];和createObject:定义如下:-(void)createObject:(ccTime)dt{intr=arc4random()%4;for(inti=0;i我想要实现的是将一些变量发送到方法中。我将函数重写为:-(void)createObject:(ccTime)dtcID:(int)cID{intr=arc4random()%4

iphone - 我们可以用什么代替 nstimer?

我可以使用[locationManagerstartUpdatingLocation]在后台获取GPS位置,但我不知道如何安排它。我已经使用NSTimer进行调度,但他们中的许多人都说如果应用程序进入后台,NSTimer将过期。如果我们不使用NSTimers,我想知道如何安排调用方法。 最佳答案 Apple提供了5种在后台运行的应用程序任务:Appsthatplayaudiblecontenttotheuserwhileinthebackground,suchasamusicplayerappAppsthatkeepusersinf

ios - block 中的弱引用与 NSTimer 之间的区别

正如我们所知,我们需要在block内使用弱引用来打破保留循环,如下所示:__weakidweakSelf=self;[selfdoSomethingWithABlock:^(){[weakSelfdoAnotherThing];}]然而,弱引用无法打破由NSTimer引起的保留周期。__weakidweakSelf=self;timer=[NSTimerscheduledTimerWithTimeInterval:30.0ftarget:weakSelfselector:@selector(tick)userInfo:nilrepeats:YES];//Noluck有什么区别?计时器怎

ios - 验证一个无效的 NSTimer

如何召回或重新建立之前失效的计时器?我试图让用户在单击按钮时重新验证/重新启动计时器。这可能吗? 最佳答案 很遗憾,没有。Fromthedocs:Onceinvalidated,timerobjectscannotbereused.只做一个新的。 关于ios-验证一个无效的NSTimer,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/25207868/

ios - NSTimer 不会因无效而停止

我这样添加定时器tim=[NSTimerscheduledTimerWithTimeInterval:1target:selfselector:@selector(repeatTim)userInfo:nilrepeats:YES];[[NSRunLoopmainRunLoop]addTimer:timforMode:NSDefaultRunLoopMode];tim它是我类​​级的NSTimer属性。然后我在点击按钮时停止它[[fbttim]invalidate];[fbtsetTim:nil];fbt它是我的类的实例。如果我只调用invalidate那么它不会停止,但是如果我将它设

objective-c - NSTimer 是线程安全的吗?

我有一个间隔为1/4秒的重复计时器。我正在这样初始化它:[NSTimerscheduledTimerWithTimeInterval:0.25target:selfselector:@selector(toggleCams)userInfo:nilrepeats:YES];这是同步发生的吗?换句话说,我能保证不会在调用toggleCams的同时调用同一个类中的另一个方法吗? 最佳答案 NSTimers实际上只是定期将事件触发到封闭的NSRunLoop中,每个线程都有(或应该有)。因此,如果您有一个子(或后台)进程在不同的线程中运行,

ios - NSTimer 用户信息。对象如何传递给选择器?

我有这个代码:-(void)startRotation:(RDUtilitiesBarRotation)mode{rotationTimer=[NSTimerscheduledTimerWithTimeInterval:0.1ftarget:selfselector:@selector(rotateSelectedItem:)userInfo:[NSNumbernumberWithInt:mode]repeats:YES];}-(void)rotateSelectedItem:(NSNumber*)sender{floatcurrAngle=[selectedItemcurrentRo

ios - 当我更改时间间隔的值时,如何更新我的 NSTimer

我有一个NSTtimer实现并且工作正常。我还将时间间隔参数连接到iPhone的UISlider。但是,当我更改它的值时,NSTimer仍在以原始时间间隔运行,它不会更新。我如何实现NSTimer并让它随着我的UISlider值的变化而改变它的时间间隔。下面是我用于NSTimer的行。[NSTimerscheduledTimerWithTimeInterval:mySlider.valuetarget:selfselector:@selector(myMethod)userInfo:nilrepeats:YES];我希望它用UISlider的值不断更新它的时间间隔。