IPhone checks consistency at run time in a universal application

I am making a universal iPad / iPhone application that can use the VGA connector for the iPad to reflect the contents of the application on an external screen. However, the iPhone does not have this feature. given the following code

#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

I get this error on the phone on startup (works fine on ipad) "dyld: Symbol not found: _UIScreenDidConnectNotification"

presumably because UIScreenDidConnectNotification does not yet exist in 3.13. How can I check this at runtime?

UPDATED ifdef statements have been added to test the ipad interface, but getting the same result!

​​ NSLog, , if . , , - ...

+5
4

UIKit. :

-all_load -ObjC -weak_framework UIKit

3.1, , 3.2, , NSClassFromString. , , . (, UIPopoverController). UIKit. , , , NULL.

, UIScreenDidConnectNotification (), .

. , , . , .

: " " , "" . UIKit .

, #ifdef , #ifdef - , UI_USER_INTERFACE_IDIOM , SDK 3.2

+3

Elfred : iPhone

if (NULL != &UIBackgroundTaskInvalid) {
   //do multitasking stuff here
} else {
   // don't do multitasking stuff here.
}
+1

" " http://iphonedevelopment.blogspot.com/2010/04/converting-iphone-apps-to-universal.html

#ifndef __IPHONE_3_2 // if iPhoneOS is 3.2 or greater then __IPHONE_3_2 will be defined
  typedef enum { // provided by noblemaster ]:-|
    UIUserInterfaceIdiomPhone, // iPhone and iPod touch style UI
    UIUserInterfaceIdiomPad, // iPad style UI
  } UIUserInterfaceIdiom;
  #define UI_USER_INTERFACE_IDIOM() (([[UIDevice currentDevice].model rangeOfString:@"iPad"].location != NSNotFound) ? UIUserInterfaceIdiomPad : UIUserInterfaceIdiomPhone)
#endif // ifndef __IPHONE_3_2 

.

0
source

Another way to loosely connect the frame is: "Get information" on your target, and on the "General" tab you will see a list of frameworks. Change the type for UIKit to weak.

This worked for me on the problem "Symbol not found: _UIScreenDidConnectNotification" on the iPhone at runtime.

0
source

All Articles