小编jos*_*hue的帖子

iPhone在通用应用程序中检查运行时的常量

我正在制作一个通用的iPad/iPhone应用程序,可以使用iPad的VGA输出连接器在外部屏幕上镜像应用程序的内容.但是,iPhone没有此功能.给出以下代码,

#ifdef UI_USER_INTERFACE_IDIOM  
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    NSLog(@"this code should not execute on iphone");
[[NSNotificationCenter defaultCenter] addObserver:self
         selector:@selector(screenInfoNotificationReceieved:) 
          name:UIScreenDidConnectNotification
           object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
         selector:@selector(screenInfoNotificationReceieved:) 
          name:UIScreenDidDisconnectNotification
           object:nil];
}
#endif
Run Code Online (Sandbox Code Playgroud)

我在启动时在手机上收到此错误(在ipad中正常工作)"dyld:找不到符号:_UIScreenDidConnectNotification"

大概是因为UIScreenDidConnectNotification在3.13中还没有存在.如何在运行时检查?

UPDATED 添加了ifdef语句来检查ipad接口,但获得了相同的结果!

UPDATED添加了NSLog语句,以确保不调用if语句中的代码.崩溃似乎发生在任何其他代码执行之前...

iphone universal ipad

5
推荐指数
1
解决办法
3249
查看次数

标签 统计

ipad ×1

iphone ×1

universal ×1