2012-12-17 75 views
0

我想在調用applicationDidEnterBackground時將一些數據從一個數組保存到一個plist文件中。我想弄清楚如何從applicationDidEnterBackground方法訪問我的數組。有沒有最佳做法來做到這一點? 非常感謝 Marcos從applicationDidEnterBackground方法保存一些數據

+0

你做了什麼研究嗎?似乎是一個常見的問題 – ekims

回答

1

將代碼放在實際具有數據的類中。讓班級註冊UIApplicationDidEnterBackgroundNotification通知。

// Put this in the `init` method 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backgrounding) name:UIApplicationDidEnterBackgroundNotification object:nil]; 

// The method that gets called 
- (void)backgrounding { 
    // save the data 
} 

// Put this in the `dealloc` method 
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil]; 

有了這個設置你沒有得到任何東西進入UIApplicationDelegate和責任保持屬於它的地方。

相關問題