我正在爲Mac OS X.我的應用程序檢查的東西每隔十秒一個應用程序,並且如果條件爲真,則應用程序發送一個低吼通知。檢查的條件在後臺每十秒鐘發送通知
我已經編碼的咆哮的通知和檢查。我只需要知道如何使此檢查每十秒鐘重複一次,並且每次都在後臺發送通知(如果爲true)。
請寫出確切的代碼,因爲我是很新的Objective-C的。謝謝:d
-------------------------------編輯---------- --------------------------
目前我使用此:
// MyApp_AppDelegate.m
#import "MyApp_AppDelegate.h"
@implementation MyApp_AppDelegate
- (void)awakeFromNib {
return;
}
-(void)applicationDidFinishLaunching:(NSNotification*)aNotification {
// grwol:
NSBundle *myBundle = [NSBundle bundleForClass:[MyApp_AppDelegate class]];
NSString *growlPath = [[myBundle privateFrameworksPath] stringByAppendingPathComponent:@"Growl-WithInstaller.framework"];
NSBundle *growlBundle = [NSBundle bundleWithPath:growlPath];
#include <unistd.h>
int x = 0;
int l = 10; // time/repeats
int t = 10; //seconds
while (x <= l) {
// more code here only to determine sendgrowl value...
if(sendgrowl) {
if (growlBundle && [growlBundle load]) {
// more code to sends growl
} else {
NSLog(@"ERROR: Could not load Growl.framework");
}
}
// do other stuff that doesn't matter...
// wait:
sleep(t);
x++;
}
}
/* Dealloc method */
- (void) dealloc {
[super dealloc];
}
@end
永遠不要在應用程序主線程上運行的方法中使用'sleep()'。整個用戶界面將凍結這段時間。 – JeremyP 2011-05-17 14:47:49
概括:做**沒有**曾經使用'sleep()'。 – bbum 2011-05-17 15:33:23
另外;考慮到您在回答問題時所提問題的基本性質,我建議您閱讀Objective-C和Cocoa入門指南。他們會幫助很多。 – bbum 2011-05-17 15:34:47