gpt4 book ai didi

iphone - 从未调用 didFinishLaunching

转载 作者:行者123 更新时间:2023-12-01 17:27:56 26 4
gpt4 key购买 nike

我创建了一个新的基于窗口的项目,但不知道为什么它什么也没做。最终,我在 didFinishLaunching 之后放置了一个 NSLog,并且在我运行它时它从未记录过。这是我编写的所有代码:

- (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]);

}

这就是我所写的全部内容,当我在模拟器或设备上运行它时,没有任何记录。有什么想法吗?

最佳答案

好吧,您在谈论应用程序委托(delegate)。显而易见的原因 - 您的对象未设置为应用程序委托(delegate) .

查看Apple文档有很多方法可以完成它:

  • 删除 Interface Builder 中的应用程序委托(delegate)绑定(bind)(窗口的 .xib 文件)
  • 将 main.h 中 UIApplicationMain 的第 4 个参数设置为 nil 以外的值。

  • 在 Interface Builder 中检查您的 nib 文件,并查看是否设置了 App Delegate。

    引用文档
    Core Application Design

    The application delegate is a custom object that you provide at application launch time, usually by embedding it in your application’s main nib file. The primary job of this object is to initialize the application and present its window onscreen. The UIApplication object also notifies this object when specific application-level events occur, such as when the application needs to be interrupted (because of an incoming message) or moved to the background (because the user tapped the Home button).



    The fourth parameter identifies the class of the application delegate. The application delegate is responsible for managing the high-level interactions between the system and your custom code. Specifying nil tells UIKit that the application delegate object is located in the application’s main nib file (which is the case for applications built using the Xcode templates).

    关于iphone - 从未调用 didFinishLaunching,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6963130/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com