开发者

example of nsnotification triggering an action when a message comes in with the subject line "WoodViolins"

开发者 https://www.devze.com 2023-01-14 08:31 出处:网络
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 messa

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...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号