2014-01-31 44 views
0

在我的应用程序中,当用户运行应用程序时,我第一次获取EKEventStore中的事件并在CoreData中本地保存它们。 对于这一点,我只想在事件存储发生任何更改时从EventStore获取事件。如何在应用程序关闭时检测EKEventStore?

我使用了EKEventStoreChangedNotification,并且在我的应用程序处于后台时在日历中添加事件时工作正常。但在应用程序关闭时它不起作用。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.eventStore = [[EKEventStore alloc]init]; 
    [self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { 
     if (granted) { 

      [[NSNotificationCenter defaultCenter] addObserver:self 
                selector:@selector(storeChanged:) 
                 name:EKEventStoreChangedNotification 
                 object:self.eventStore]; 
     } 
    }]; 
return YES; 
} 

-(void)storeChanged:(NSNotification *)notif { 

    // Update core data 
} 

回答

0

你试过把一个观察者

- (void)applicationDidEnterBackground:(UIApplication *)application 
{ 

} 

你的AppDelegate?

+0

我想这只会照顾当我的应用程序在后台和runnig但什么时候我的应用程序甚至没有运行(甚至不在后台) – Ashutosh

+1

当你的应用程序不是没有机会对新事件作出反应活性。每次运行应用程序时都必须检查EKEventStore。 –

相关问题