gpt4 book ai didi

objective-c - 每十秒检查一次后台状况并发送通知

转载 作者:行者123 更新时间:2023-12-03 17:16:10 24 4
gpt4 key购买 nike

我正在开发一个适用于 Mac OS X 的应用程序。我的应用程序每十秒检查一次,如果条件成立,该应用程序会发送一条 Growl 通知。

我已经对 Growl 通知和检查进行了编码。我只需要知道如何使此检查每十秒重复一次,并且每次在后台发送通知(如果为真)。

请写出准确的代码,因为我对 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

最佳答案

您正在寻找的确切代码可以在这里找到: Time Programming Topics

关于objective-c - 每十秒检查一次后台状况并发送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6031651/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com