2012-03-23 7 views
0

アプリケーションを終了または最小化するときにデータを保存しようとしていますが、applicationwillenterbackgroundが呼び出されないようです。私は何か特別なことをする必要がありますか?ios applicationwillenterbackgroundが呼び出されていない

detailview.hクラスに<UIApplicationDelegate>を設定しましたが、運がまだありません。

ちなみに、これがrelaventの場合、私はMaster-DetailView templeteを使用しています。

答えて

1

-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]; 
} 
+0

私はそれらを呼び出すがどちらも実行されません。テキストビューのように[self.textView setDelegate:self]のように委任を設定する必要はありますか? –

+0

アプリケーションデリゲートでこれらのメソッドを定義していない可能性はありますか? UIApplicationDelegateプロトコルを実装する1つのクラスだけがこれらのメッセージを取得します。このクラスも '-application:didFinishLaunchingWithOptions'を定義する必要があり、通常は' AppDelegate'で終わる名前を持っています。それは役に立ちますか? – vbwx

関連する問題