Two versions of an app- one iPhone and one iPod touch

Discussion in 'iPhone/iPad Programming' started by I'm a Mac, Feb 24, 2009.

  1. macrumors 6502

    Joined:
    Nov 5, 2007
    #1
    Does anyone know if it's possible to make two versions of the same app (same title) - one for the iPhone and one for the iPod touch? If so, how would you do this? would you submit two different apps? Would both apps show up in the app store under the same title and the device would automatically choose?

    Thanks.
     
  2. macrumors 68000

    Joined:
    Nov 3, 2007
    #2
    Why not just build your app to interact with touches differently then phones?
     
  3. thread starter macrumors 6502

    Joined:
    Nov 5, 2007
    #3
    I'm not quite sure what you mean, but there's only a small difference that I need for for the two devices on my app. I have an image view, and for an iPhone, I want it to load a certain image, and for an iPod touch, I want it to load a different image. Is there anyway I would be able to do that without having the user go into some sort of preferences?
     
  4. macrumors regular

    Joined:
    Jul 12, 2008
    #4
    I'm pretty certain you can query the device to find out what it is, then use some simple if and else logic.
     
  5. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Agreed. You certainly can. The model property of UIDevice contains either @”iPhone” or @”iPod touch”.
     
  6. thread starter macrumors 6502

    Joined:
    Nov 5, 2007
    #6
    So how would I fit that into an ApplicationDidFinishLaunching method? I'm sorry I'm sort of new at programming
     
  7. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    If you're not sure how to put together a simple if-then-else test that is based on the property of a built-in class, I would suggest that you need to spend a bunch more time learning the basics of Objective-C coding before you go much further. Being new to programming is not a bad thing. It just means you have some learning to do before you can be competent enough to start coding that next-great iPhone app. You could start by looking at the stickies and guides at the top of this iPhone Programming forum.
     
  8. macrumors 68000

    Joined:
    Nov 3, 2007
    #8
    I think his problem is getting the device, no the if statement.

    Code:
    UIDevice *myCurrentDevice = [UIDevice currentDevice];
    NSString *theDevice = [NSString stringWithFormat=@"%@",[myCurrentDevice model]];
    That will return either iPod Touch, iPhone, or Simulator depending on which device it is on.

    Then you will simply compare the strings against @"iPhone" or whatever and perform the proper image loading for the device.
     
  9. thread starter macrumors 6502

    Joined:
    Nov 5, 2007
    #9
    Double post. Sorry.
     
  10. thread starter macrumors 6502

    Joined:
    Nov 5, 2007
    #10
    Thank you. It was partly my fault, I phrased the question poorly, but I'm glad you understood me. I would consider myself fairly competent in understanding Objective-c, I'm just not completely familiar with all of the Cocoa and Cocoa touch methods
     
  11. thread starter macrumors 6502

    Joined:
    Nov 5, 2007
    #11
    Thanks you so much for all of your help. Now, it appears I'm having an Objective-C issue. For some reason, even though I can get the model name, my iPhone won't respond to the if loop for it's correct model name (it just goes to else)

    Code:
    - (void)applicationDidFinishLaunching:(UIApplication *)application {    
    	
    	UIDevice *myCurrentDevice = [UIDevice currentDevice];
    	NSString *theDevice = [NSString stringWithFormat:@"%@",[myCurrentDevice model]];
    	NSLog(@"The current model is %@", theDevice);
    //The Debugger logs that the model is indeed an iPhone
    	
    	if (theDevice == @"iPhone") {
    		NSLog(@"Using the iPhone");
    //That is not getting logged
     
  12. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #12
    Try
    Code:
    if ([theDevice isEqual:@"iPhone"])
    instead.

    The == is simply comparing pointer values, which will always be different for your code since you're allocating theDevice's own memory space through the stringWithFormat call.
     
  13. thread starter macrumors 6502

    Joined:
    Nov 5, 2007
    #13
    Thanks, it worked.
     

Share This Page