我創建了一個新的基於窗口的項目,並不知道爲什麼它沒有做任何事情。最後我在didFinishLaunching之後放了一個NSLog,並且在運行它時從未記錄過。下面是我自己編寫的代碼:didFinishLaunching從未被稱爲
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"didFinishLaunching");
// Get the device object and turn proximity monitoring on
UIDevice *d = [UIDevice currentDevice];
[d setProximityMonitoringEnabled:YES];
// Get the NSNotificationCenter object
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
// Sign up to receive notifications when the proximity state changes
[nc addObserver:self selector:@selector(proximityChanged:) name:UIDeviceProximityStateDidChangeNotification object:d];
NSLog(@"Observing...");
[self.window makeKeyAndVisible];
return YES;
}
- (void)proximityChanged:(NSNotification *)note {
// Print out the changes of proximity state
NSLog(@"Proximity Changed: %d", [[note object] proximityState]);
}
那是什麼,我已經寫了,當我在模擬器或設備上運行它沒有被記錄的完整。有什麼想法嗎?