iPad only code in universal app

Discussion in 'iOS Programming' started by uaecasher, Jun 2, 2010.

  1. uaecasher macrumors 65816

    uaecasher

    Joined:
    Jan 29, 2009
    Location:
    Stillwater, OK
    #1
    Hello,

    I'm trying to make a conditional statement to remove a code if the device is not iPad, my app is a universal app.

    here is the code:

    Code:
    
    - (IBAction)presentMasterInPopoverFromBarButtonItem:(UIBarButtonItem *)barButtonItem {
    	if ([UIDevice instancesRespondToSelector:@selector(userInterfaceIdiom)]&&[[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
    	UIImagePickerController* picker = [[UIImagePickerController alloc] init]; 
    	picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    	picker.delegate = self; 
    		
    	UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
    	self.popoverController = popover; 
    	[popover release];
    	[popoverController presentPopoverFromBarButtonItem:barButtonItem  permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    	
    	[picker release];
    
    	} else {
    		 NSLog(@"iPhone Idiom");
    	}
    
    } 
    
    
    that code isn't working and my app is crashing on any iPhone/iPod, I tried another code provided by apple team in their forum

    Code:
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    
    but it doesn't work either.

    i get this error:

    Code:
    
    dyld: Symbol not found: _OBJC_CLASS_$_UIPopoverController
      Referenced from: /var/mobile/Applications/F04EED5E-8150-4477-8E1C-855CD74D6198/Pixels.app/Pixels
      Expected in: /System/Library/Frameworks/UIKit.framework/UIKit
    
    
    any help please?
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    Code:
    - (IBAction)presentMasterInPopoverFromBarButtonItem:(UIBarButtonItem *)barButtonItem {
    	if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    	UIImagePickerController* picker = [[UIImagePickerController alloc] init]; 
    	picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
    	picker.delegate = self; 
    		
    	UIPopoverController *popover = [[NSClassFromString(@"UIPopoverController"); alloc] initWithContentViewController:picker];
    	self.popoverController = popover; 
    	[popover release];
    	[popoverController presentPopoverFromBarButtonItem:barButtonItem  permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    	
    	[picker release];
    
    	} else {
    		 NSLog(@"iPhone Idiom");
    	}
    
    }
     
  3. KoolStar macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #3
    Are you building for 3.2 with deployment target set to 3.0
     
  4. uaecasher thread starter macrumors 65816

    uaecasher

    Joined:
    Jan 29, 2009
    Location:
    Stillwater, OK
    #4
    yup, I did what the about post did and it worked, thanks for help anyway.
     
  5. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #5
    I use:
    Code:
    #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
                    globalFlagForIPad = YES;
        }
        if (globalFlagForIPad) {
            iPad stuff...
        }
    #endif
    
    so that my code is portable to 3.0 projects as well as 3.2.
     

Share This Page