【问题标题】:AppDelegate not being called on iOS / Allegro 5AppDelegate 未在 iOS / Allegro 5 上调用
【发布时间】:2023-03-17 06:37:01
【问题描述】:

-- 我的 appdelegate.m 在所有其他默认调用中都有这个:--

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    [self.window makeKeyAndVisible];
    NSLog(@"Launched");
    return YES;
}

-- 我的 main.mm 看起来像这样:--

#import <UIKit/UIKit.h>

#import "AppDelegate.h"
#include <allegro5/allegro.h>
ALLEGRO_DISPLAY *Display;

int main(int argc, char *argv[])
{
    al_init();
    al_set_new_display_option(ALLEGRO_SUPPORTED_ORIENTATIONS,
                           ALLEGRO_DISPLAY_ORIENTATION_LANDSCAPE,ALLEGRO_REQUIRE);
    Display = al_create_display(960, 640);
    printf("%d, %d", al_get_display_width(Display),                
                    al_get_display_height(Display));

    return 0;
}

只要我在项目中包含 allegro.h 和所有必需的库/框架并在 main 中调用 al_init(),程序就会停止打印“已启动”。似乎 AppDelegate 被完全忽略了。有人有什么建议吗???

【问题讨论】:

  • 在 AppDelegate 中覆盖 -(void)applicationDidBecomeActive:(UIApplication *)application 并在其中放置一个 NSLog 以查看它是否到达那里。然后,如果您调试打印,您就会知道它会到达 App Delegate。
  • 你也可以看看-(void)applicationWillEnterForeground:(UIApplication *)application

标签: ios appdelegate uiapplication allegro


【解决方案1】:

您应该设置一个整数返回值,而不是返回 0:

   int retVal = UIApplicationMain(argc, argv, nil, nil);
   return retVal;

   return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

这可能行得通。

【讨论】:

  • 我试过 return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); ///---/// 应用程序编译但将其作为输出: ///---/// *** Assertion failure in void UIApplicationInstantiateSingleton(Class)(), /SourceCache/UIKit_Sim/UIKit-2380.17/ UIApplication.m:2037 *** 由于未捕获的异常而终止应用程序
    'NSInternalInconsistencyException',原因:'只能有一个 UIApplication 实例。'
  • 做了第一个,UIApplicationMain(argc, argv, nil, nil);产生不同的结果?
  • 重写 applicationDidBecomeActive 是什么意思?我是否必须创建 UIApplicationDelegate 的子类,然后覆盖超类的方法(在他的情况下为 UIApplicationDelegate)?我是一名初学者 iOS 程序员。
  • 不只是将它添加到您的 AppDelegate.m 并放入 NSLog(@"Launched");在那里查看应用程序是否到达您的 AppDelegate。
  • 我试过了。实际上,我已将 NSLog 放置到 AppDelegate.h 中的每个方法(applicationDidEnterBackground、applicationWillEnterForeground 等)中。没有任何输出。
【解决方案2】:

Allegro 程序在源代码级别是跨平台的。因此,您不需要提供 AppDelegate,因为 Allegro 已经这样做了。操作系统事件将转换为 Allegro 事件,您可以跨平台方式响应。

如果您真的需要自己的 AppDelegate,那么您需要编辑 Allegro 的源代码。

【讨论】:

    【解决方案3】:

    Allegro 5.1 没有设置 rootViewController。我修改了 allegro 源代码来做到这一点,现在一切都可以在 iOS 6.0/6.1 上运行。

    我在 ViewController.m 中添加了 shouldAutorotatesupportedInterfaceOrientations 方法 并添加了 window.rootViewController = vc;在 allegroAppDelegate.m 下的“static void iphone_add_screen(UIScreen *screen)”-方法中。然后我重新编译了allegro。

    感谢大家的帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-13
      • 1970-01-01
      相关资源
      最近更新 更多