-applicationDidEnterBackground:
を使用してユーザーデータを保存します。これは、バッテリーが消耗した場合に呼び出される可能性のある-applicationWillTerminate:
でも行われるはずです。 ApplicationWillTerminate in iOS 4.0
私のアプリでは、この問題を広範に調査し、前述の両方の方法を実装する以外に、デバイスがマルチタスキングをサポートしているかどうかを確認しなければならないことがわかりました。 (例えば、iPhone 3Gの場合)。だからここに私のコードの一部がどのように見えるのですか:
- (void) applicationDidEnterBackground:(UIApplication*)application
{
// This is called on all iOS 4 devices, even when they don't support multi-tasking.
// But we want to avoid saving data twice, so we check.
if ([[UIDevice currentDevice] respondsToSelector:@selector(isMultitaskingSupported)])
[model serializeEntries];
}
- (void) applicationWillTerminate:(UIApplication*)application
{
// This is always called on devices that don't support multi-tasking,
// but also in low-memory conditions and when the app has to be quit for some
// other reason.
[model serializeEntries];
}
私はそれらを呼び出すがどちらも実行されません。テキストビューのように[self.textView setDelegate:self]のように委任を設定する必要はありますか? –
アプリケーションデリゲートでこれらのメソッドを定義していない可能性はありますか? UIApplicationDelegateプロトコルを実装する1つのクラスだけがこれらのメッセージを取得します。このクラスも '-application:didFinishLaunchingWithOptions'を定義する必要があり、通常は' AppDelegate'で終わる名前を持っています。それは役に立ちますか? – vbwx