そのため、何が起こっているのかをよりよく理解するためにできることは次のとおりです。
アプリの main.m に、これを追加します。
@interface GTTestObject : NSObject
- (void)logNotification:(id)sender;
@end
@implementation GTTestObject
- (void)logNotification:(id)sender {
NSLog(@"%@", [(NSNotification *)sender name]);
}
@end
int main(int argc, char *argv[])
{
@autoreleasepool {
// I'm assuming you'd be using ARC...
GTTestObject *obj = [[GTTestObject alloc] init];
[[NSNotificationCenter defaultCenter] addObserver:obj selector:@selector(logNotification:) name:nil object:nil];
return UIApplicationMain(argc, argv, nil, NSStringFromClass([GTAppDelegate class]));
}
}
次に、すべてのMyAppDelegate.m
メソッドについて「...didFinishLaunching、...didEnterBackgroundなど」。これを追加:
NSLog(@"[%@ %@]", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
これで、シーケンス、タイムスタンプ、および (おそらく) 同時に発生した通知/デリゲート呼び出しとの競合を確認できます。
テストごとにわずかに異なる結果が得られる可能性があるため、確認するために数回実行してください。
実行例については、毎回これを確認します。
2012-12-21 08:13:58.559 Gamerton[34158:c07] [GTAppDelegate application:didFinishLaunchingWithOptions:] state: UIApplicationStateInactive
2012-12-21 08:13:58.560 Gamerton[34158:c07] UIApplicationDidFinishLaunchingNotification state: UIApplicationStateInactive
...
2012-12-21 08:13:58.561 Gamerton[34158:c07] [GTAppDelegate applicationDidBecomeActive:] state: UIApplicationStateActive
2012-12-21 08:13:58.561 Gamerton[34158:c07] UIApplicationDidBecomeActiveNotification state: UIApplicationStateActive
... Hit home button
2012-12-21 08:16:08.227 Gamerton[34170:c07] [GTAppDelegate applicationWillResignActive:] state: UIApplicationStateActive
2012-12-21 08:16:08.228 Gamerton[34170:c07] UIApplicationWillResignActiveNotification state: UIApplicationStateActive
2012-12-21 08:16:08.229 Gamerton[34170:c07] UIApplicationSuspendedNotification state: UIApplicationStateBackground
2012-12-21 08:16:08.229 Gamerton[34170:c07] [GTAppDelegate applicationDidEnterBackground:] state: UIApplicationStateBackground
... Reopen app
2012-12-21 08:16:59.364 Gamerton[34170:c07] [GTAppDelegate applicationWillEnterForeground:] state: UIApplicationStateBackground
2012-12-21 08:16:59.365 Gamerton[34170:c07] UIApplicationWillEnterForegroundNotification state: UIApplicationStateBackground
2012-12-21 08:16:59.365 Gamerton[34170:c07] _UIApplicationDidRemoveDeactivationReasonNotification
2012-12-21 08:16:59.366 Gamerton[34170:c07] [GTAppDelegate applicationDidBecomeActive:] state: UIApplicationStateActive
2012-12-21 08:16:59.366 Gamerton[34170:c07] UIApplicationDidBecomeActiveNotification state: UIApplicationStateActive
2012-12-21 08:16:59.366 Gamerton[34170:c07] UIApplicationResumedNotification state: UIApplicationStateActive
2012-12-21 08:16:08.230 Gamerton[34170:c07] UIApplicationDidEnterBackgroundNotification state: UIApplicationStateActive