Para repetir una llamada al método (o enviar mensaje, supongo que el término apropiado es) cada x segundos, es mejor utilizar un NSTimer (de NSTimer scheduledTimerWithTimeInterval: objetivo: Selector: userInfo: repite :) o tener el método recurrentemente se llama a sí mismo al final (usando performSelector: withObject: afterDelay)? Este último no usa un objeto, pero tal vez es menos claro/legible? Además, solo para darle una idea de lo que estoy haciendo, es solo una vista con una etiqueta que cuenta hasta las 12:00 de la medianoche, y cuando llega a 0, parpadea el tiempo (00:00:00) y ejecute un pitido para siempre.iPhone dev - performSelector: withObject: afterDelay o NSTimer?
Gracias.
Editar: también, ¿cuál sería la mejor manera de reproducir repetidamente un SystemSoundID (para siempre)? Editar: Terminé usando esto para reproducir el SystemSoundID siempre:
// Utilities.h
#import <Foundation/Foundation.h>
#import <AudioToolbox/AudioServices.h>
static void soundCompleted(SystemSoundID soundID, void *myself);
@interface Utilities : NSObject {
}
+ (SystemSoundID)createSystemSoundIDFromFile:(NSString *)fileName ofType:(NSString *)type;
+ (void)playAndRepeatSystemSoundID:(SystemSoundID)soundID;
+ (void)stopPlayingAndDisposeSystemSoundID;
@end
// Utilities.m
#import "Utilities.h"
static BOOL play;
static void soundCompleted(SystemSoundID soundID, void *interval) {
if(play) {
[NSThread sleepForTimeInterval:(NSTimeInterval)interval];
AudioServicesPlaySystemSound(soundID);
} else {
AudioServicesRemoveSystemSoundCompletion(soundID);
AudioServicesDisposeSystemSoundID(soundID);
}
}
@implementation Utilities
+ (SystemSoundID)createSystemSoundIDFromFile:(NSString *)fileName ofType:(NSString *)type {
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:type];
SystemSoundID soundID;
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
return soundID;
}
+ (void)playAndRepeatSystemSoundID:(SystemSoundID)soundID interval:(NSTimeInterval)interval {
play = YES
AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL,
soundCompleted, (void *)interval);
AudioServicesPlaySystemSound(soundID);
}
+ (void)stopPlayingAndDisposeSystemSoundID {
play = NO
}
@end
parece funcionar bien .. Y para el sello parpadear Voy a usar un NSTimer supongo.
Esto es útil para contrastar los dos métodos. –