Can someone show an example of this in objective-c? I have the addressbook framework and mail core to get the inbox. I don't know how to have it keep checking for new messages and notify when a message comes in with a specific subject.
Eli开发者_StackOverflow社区jah
MailCore can not send you automatic notifications when things change. Using this framework, you'll have to periodically ping the server. Create a NSTimer:
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(refresh:) userInfo:nil repeats:YES];
E.g. add a property for the last seen message count: @property NSUInteger lastMessageCount;
Then write the polling method:
- (void)refresh:(NSTimer *)aTimer {
// given a CTCoreFolder *folder
NSUInteger count = [folder totalMessageCount];
if (count != self.lastMessageCount)
[[NSNotificationCenter defaultCenter] postNotificationName:@"FolderUpdated" object:folder];
self.lastMessageCount = count;
}
You can now observe that notification and be informed on every folder change. Should be quite easy for you to adjust it to your needs now...
精彩评论