jjzjj

ios - 将 completionHandler 传递给 NSTimer

在iOS7中,他们添加了函数-(void)application:(UIApplication*)applicationdidReceiveRemoteNotification:(NSDictionary*)userInfofetchCompletionHandler:(void(^)(UIBackgroundFetchResult))completionHandler它允许你当您收到推送通知时在后台执行某些操作。然而,他们只给你大约30秒的时间来做某事。我想制作一个NSTimer,让我知道我的30秒是否快到,并让它完成它正在做的事情。通过计时器传递完成处理程序会很好,这样我就可以在完

ios - UIAlertController 标题中的倒计时 NSTimer 获取空值而不是时间(以秒为单位)

我试图在UIAlertController的标题中显示倒计时。我想要类似“您的session将在X秒后到期”的内容。我的想法是创建一个NSTimer并将时间存储在NSStringstringWithFormat中,并将该字符串作为警报Controller的标题。这是我的倒计时方法:@interfaceViewController(){NSString*seconds;intmainInt;NSTimer*timer;}-(void)countDown{mainInt=20;mainInt-=1;seconds=[NSStringstringWithFormat:@"%i",mainIn

iPhone 4 是否有绝对确定的方式让 NSTimer 长期运行

我的NSTimers和背景选择器一直有问题。这让我抓狂,每次调整都需要很长时间。为了保持我的理智,以及后代cocoa程序员的理智,我问这个问题:是否有绝对100%确定的方法可以在稍后的时间点触发一个预定的长期计时器,而不管它是从后台线程、主线程等调用的?对于大多数使用NSTimers的类,我似乎一直不得不一遍又一遍地解决同样的问题。它们在短期测试期间工作,比方说我将计时器设置为通过后台线程触发以在10秒内触发。它有效,因为仍然有一个运行循环在运行。但是一旦我将点火时间更改为我真正想要的时间,比如15-30分钟,就会一片死寂。运行循环消失了,我不知道如何处理这种情况。什么都没有发生,几天

iphone 开发 : how to create an animation by using NSTimer

在我的应用程序中,我在viewWillAppear中有这段代码。它只是将随机对象从屏幕顶部动画化到底部。问题是我需要检测碰撞,到目前为止我学到的是不可能随时检索动画的坐标。那么如何使用NSTimer实现它呢?还是应该使用NSTimer?我想不通。任何线索将不胜感激。-(void)viewWillAppear:(BOOL)animated{for(inti=0;i 最佳答案 我会放弃NSTimer而使用CADisplayLink来向您的目标发送消息。NSTimer可能会导致动画断断续续,因为它与设备的屏幕刷新率不同步。CADispla

ios - dispatch_after 递归 vs NSTimer scheduledtimerwithtimeinterval

我读了一段代码,它每秒检查数据并更新UI。这听起来像我们通常使用NSTimerscheduledtimerwithtimeinterval所做的事情。但是这段代码是通过递归调用dispatch_after实现的,如下所示:-(void)retriggerMethod{...dostuffhere,assumingyouwanttodoitonfirstinvocation...dispatch_after(...,^{[selfretriggerMethod];});}dispatch_afterrecursion和NSTimerscheduledtimerwithtimeinterv

ios - NSTimer 不会停止

[selfperformSelectorInBackground:@selector(method)withObject:nil];-(void)method{timer1=[NSTimerscheduledTimerWithTimeInterval:1target:selfselector:@selector(getLastImageName1)userInfo:nilrepeats:YES];runLoop=[NSRunLoopcurrentRunLoop];[runLoopaddTimer:timer1forMode:NSRunLoopCommonModes];[runLoopr

ios - self 弱的 NSTimer;为什么不调用 dealloc?

考虑具有强(或弱,相同)NSTimer属性的ViewController:__weak__typeof(self)ws=self;self.timer=[NSTimerscheduledTimerWithTimeInterval:2target:wsselector:@selector(timerTigger:)userInfo:nilrepeats:YES];但为什么这个ViewController不调用dealloc方法,无论我通过strong还是weak引用到self?详细代码如下:#import"SecondViewController.h"@interfaceSecondVi

objective-c - 使用 NSTimer 显示每秒帧数时间码

我正在开发一个需要显示运行时间码时钟的iPhone/iPad应用程序。使用此代码,我可以毫无问题地显示正确的小时、分钟和秒:-(void)viewDidLoad{//StarttheTimermethodforheretostartitwhentheviewloads.runTimer=[NSTimerscheduledTimerWithTimeInterval:.01target:selfselector:@selector(updateDisplay)userInfo:nilrepeats:YES];}-(void)updateDisplay{NSDateFormatter*for

ios - 将 startMonitoringSignificantLocationChanges 与 NSTimer 结合使用以提高电池使用率

我目前正在开发其他开发者开发的iOS应用程序。该应用程序需要监视位置变化,因为它需要了解低精度(百米)的用户位置。位置信息的先前实现是使用NSTimer和startUpdatingLocation完成的。执行过程如下://Fireeach10secondsstartupdatinglocationself.timerPosition=[NSTimerscheduledTimerWithTimeInterval:titarget:selfselector:@selector(location)userInfo:nilrepeats:YES];[self.timerPositionfire

ios - NSOperation with NSTimer循环如何停止它

我的NSOperationQueue在另一个线程上运行,而不是在整个应用程序上运行。我正在将NSOperation添加到main中的队列中-(void)main{[selfupdatePallets];NSTimer*timer=[NSTimerscheduledTimerWithTimeInterval:5.0target:selfselector:@selector(updatePallets)userInfo:nilrepeats:Yes];NSRunLoop*runLoop=[NSRunLoopcurrentRunLoop];[runLoopaddTimer:timerforM