x秒ごとにメソッド呼び出しを繰り返すには、NSTimer(NSTimerのscheduledTimerWithTimeInterval:target:selector:userInfo:repeats :)を使用するか、再帰的に(performSelector:withObject:afterDelayを使用して)最後に自身を呼び出しますか?後者はオブジェクトを使用しませんが、あまり明確でない/読みやすいでしょうか?また、ちょうど私がやっていることのアイデアを与えるために、それはちょうど夜12時までカウントするラベルを持つビューで、0になると時刻(00:00:00)を点滅させます。永遠にビープ音を鳴らします。iPhoneのdev - performSelector:withObject:afterDelayまたはNSTimer?
ありがとうございました。
編集:SystemSoundID(永遠)を繰り返し再生するにはどうすればよいでしょうか? 編集:私は永遠にSystemSoundIDを再生するには、このを使用して終了:
// 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
が正常に動作するようです...とラベルのため、私は私が推測NSTimerを使用します点滅します。
これは、2つの方法を対比するのに役立ちます。 –