【发布时间】:2011-11-23 15:28:00
【问题描述】:
我一直在寻找答案,但没有任何效果。
我有一个 NSTimer 作为 Appdelegate 的属性,这个 NSTimer 应该在任何时候触发他的动作,即使应用程序在后台(它是一个本地化应用程序 - 所以它可以永远运行)
这是代码:
if(conectar){
self.myTimer = [[NSTimer scheduledTimerWithTimeInterval:10.0
target:self
selector:@selector(abrirPresencia)
userInfo:nil
repeats:NO]retain];
}
else{
self.myTimer = [[NSTimer scheduledTimerWithTimeInterval:10.0
target:self
selector:@selector(cerrarPresencia)
userInfo:nil
repeats:NO]retain];
}
应用程序崩溃 10 秒后,我在两个方法中都有断点并且它不会停止,就好像该方法甚至没有被调用,而不是触发它崩溃的方法。
方法如下:
-(void)cerrarPresencia{
NSLog(@"SOY EL TIMERRRRR!!!! %@");
//[[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground
if (YES){
[self.location stopUpdatingLocation];
[self disconnect];
}
else{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Ups!"
message:@"Según tu perfil querrías estar desconectado pero como lo estás usando hemos incluido este horario. Para cambiarlo sólo tienes que ir a editar perfil."
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
[alertView release];
}
}
-(void)abrirPresencia{
NSLog(@"SOY EL TIMERRRRR!!!! %@");
if (YES){
[self.location stopUpdatingLocation];
[self disconnect];
}
else{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Ups!"
message:@"Según tu perfil querrías estar desconectado pero como lo estás usando hemos incluido este horario. Para cambiarlo sólo tienes que ir a editar perfil."
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
[alertView release];
}
}
属性是:
@property (nonatomic, retain)NSTimer *myTimer;
有什么想法吗?
【问题讨论】:
-
你能发布这些方法吗?崩溃日志中有什么错误?
-
如果你调用的方法有一个(或多个)参数,你应该在选择器的末尾添加一个冒号:。你能按照@Vladimir 的要求做并发布方法吗?
-
很可能这是一个 SIGABRT。尝试在选择器名称中添加“:”。例如:(cerrarPresencia:)
-
能否也粘贴 myTimer 的属性?
标签: objective-c