我想知道如何在我的應用程序的NSTimer在後臺觸發時獲取本地通知。我的NSTimer在後臺每隔10分鐘檢查一次文件夾的文件。如果找到文件,我將如何去接收本地通知?如果確定文件夾不是空的,如何獲取本地通知?
編輯:代碼:
- (void) createTimeThread: (float) pIntervalTime
{
[NSThread detachNewThreadSelector:@selector(startTimerThread)
toTarget:self withObject:nil];
}
- (void) startTimerThread
{
UIBackgroundTaskIdentifier bgTask = [[UIApplication sharedApplication]
beginBackgroundTaskWithExpirationHandler:^{}];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSRunLoop* runLoop = [NSRunLoop currentRunLoop];
myTimer = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(conditionChecking:)
userInfo:nil
repeats:YES];
[runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
[pool release];
[[UIApplication sharedApplication] endBackgroundTask:bgTask];
}
- (void)conditionChecking:(NSIndexPath *)indexPath
{
NSString *pathForFile = @"/User/Library/Logs/CrashReporter";
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:pathForFile]) { // Directory exists
NSArray *listOfFiles = [fileManager contentsOfDirectoryAtPath:pathForFile error:nil];
if (!listOfFiles || !listOfFiles.count)
{
NSLog(@"No Core Dumps found.....");
}
else
{
NSLog(@"Core Dump(s) found! :%@", listOfFiles);
}
}
}
您的標籤與您的問題衝突 - 您是要求推送通知還是本地通知? – BoltClock
不明白你的問題是什麼。您是否正在尋找'NSTimer'的替代品,或者只是想知道如果發現文件時如何通知? – Saphrosit
我只想知道如何在後臺獲取通知。 –