1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

two app versions

Discussion in 'iPhone/iPad Programming' started by uaecasher, Dec 9, 2009.

  1. macrumors 65816

    uaecasher

    #1
    hello,

    I'm wondering how can I make iPod only version of my app as there is some features that require a camera and if i use that app on the iPod it will crash, what should I do? should I create two independent apps or is there a code to check the device and strip out the code? any documentation links?

    thanks
     
  2. Moderator

    robbieduncan

    Staff Member

    #2
    You should check at runtime if the camera is available and write your code correctly so as it does not crash if it's not.
     
  3. macrumors 65816

    uaecasher

    #3
    I'm not sure how this is done, any links for documentation or other tutorials, thanks in advance
     
  4. Moderator

    robbieduncan

    Staff Member

    #4
    It's right there in the UIImagePickerController documentation.
     
  5. macrumors 65816

    uaecasher

    #5
    Ok I feel really noob right now :eek: I have disabled the action now but how can I remove the button it self from the view.

    Thanks
     
  6. Moderator

    dejo

    Staff Member

    #6
    Code:
    [button removeFromSuperView];
     
  7. macrumors 65816

    uaecasher

    #7

    I tired it now, but it removes the button after i selected the 1st one and chose the image from library, here is my code:

    Code:
    
    
    #import "testPickerViewController.h"
    
    @implementation testPickerViewController
    
    @synthesize imgPicker;
    @synthesize imgPickerCam;
    @synthesize spinner;
    
    
    
    
    
    - (IBAction)grabImage {
    	if ( (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]))
    
    		
    	{				
    		
    		
    		if(imgPicker == nil){
    	self.imgPicker = [[UIImagePickerController alloc] init];
    	self.imgPicker.delegate = self;	
    	self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    	[self presentModalViewController:self.imgPicker animated:YES];
    			[button removeFromSuperview];
    		}
    	
    
    }
    
    }
    		-(IBAction)grabImageCam {
    			
    			
    			
    			
    					
    	self.imgPickerCam = [[UIImagePickerController alloc] init];
    	self.imgPickerCam.delegate = self;
    	self.imgPickerCam.sourceType = UIImagePickerControllerSourceTypeCamera;
    	[self presentModalViewController:self.imgPickerCam animated:YES];
    				
    }
    
    
    
    
    
    
      - (IBAction)uploadImage {
    	  [spinner startAnimating];
    	/*
    	 turning the image into a NSData object
    	 getting the image back out of the UIImageView
    	 setting the quality to 90
    	 */
    	  
    	  [spinner stopAnimating];
    	  
    	NSData *imageData = UIImageJPEGRepresentation(image.image, 100);
    	  
    
    	// setting up the URL to post to
    	NSString *urlString = @"http://mozymac.com/upload.php";
    	
    	// setting up the request object now
    	NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
    	[request setURL:[NSURL URLWithString:urlString]];
    	[request setHTTPMethod:@"POST"];
    	
    	/*
    	 add some header info now
    	 we always need a boundary when we post a file
    	 also we need to set the content type
    	 
    	 You might want to generate a random boundary.. this is just the same 
    	 as my output from wireshark on a valid html post
    	 */
    	NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
    	NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
    	[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
    	
    	/*
    	 now lets create the body of the post
    	 */
    	NSMutableData *body = [NSMutableData data];
    	[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];	
    	[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"userfile\"; filename=\".jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    	[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    	[body appendData:[NSData dataWithData:imageData]];
    	[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    	// setting the body of the post to the reqeust
    	[request setHTTPBody:body];
    	
    	// now lets make the connection to the web
    	NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    	NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
    	  
    	
    	myTextField.text = (returnString);
    	
    	 
    	
    }
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
    	image.image = img;	
    
    	[[picker parentViewController] dismissModalViewControllerAnimated:YES];
    	[spinner startAnimating];
    	// need to show the upload image button now
    	upload.hidden = NO;
    }
    @end
    
    
    
     
  8. Moderator

    dejo

    Staff Member

    #8
    Then you need to move the removeFromSuperview call to a more appropriate place in the code.
     
  9. macrumors 65816

    uaecasher

    #9
    I tired moving it around but all places didn't work, that's why I posted my code hoping you could help me find the correct place :D
     
  10. Moderator

    dejo

    Staff Member

    #10
    Is removing the button, in and of itself, not working? If this is the case, where have you set the value of button?

    If the button is being removed okay but just not at the right time, sit back and think about where, as the code executes, views are set up, etc., you want the button to not appear. That should help identify where you need to put the call.
     
  11. macrumors 65816

    uaecasher

    #11
    it's seniro number two, after the application is loaded the two buttons appear, when I select the library one then select a photo, the 2nd one is then gone.
     
  12. Moderator

    dejo

    Staff Member

    #12
    And when do you actually want the button to no longer appear? After the application (view) is loaded?
     
  13. macrumors 65816

    uaecasher

    #13
    yeah
     
  14. Moderator

    dejo

    Staff Member

    #14
    If only there was an instance method that let you know when a view Did Load... ;)
     
  15. macrumors 65816

    uaecasher

    #15

    :D thanks it works now, I don't know how i forgot about that LOL. Thanks again.

    by the way, someone told me it's not allowed to have 2 looks for my apps i.e (one for iphone and ipod) and that apple would probably reject my app if I did so, what are thoughts about this.

    Thanks :D
     
  16. Moderator

    robbieduncan

    Staff Member

    #16
    There must be other apps out there that present different interfaces based on camera availability. Probably hundreds of them...
     
  17. Moderator

    dejo

    Staff Member

    #17
    You're welcome. Don't forget to rely on the documentation, especially the Class References. They're there to help you.

    Actually, for what you are doing, Apple would reject it if you left the button when running on an iPod touch. They don't like you to leave UI elements for things that are unsupported. For [app]CraigsHarvest Lite[/app], we had to remove a button that only worked in the full version. We couldn't use it as an opportunity to remind the user of the availability of the full version.
     
  18. macrumors 65816

    uaecasher

    #18
    one of them is facebook, anyways thanks for help guys.

    I do need help in another thread though, so if your interested, your welcome to visit :D

    http://forums.macrumors.com/showthread.php?p=8933805#post8933805
     
  19. macrumors 65816

    uaecasher

    #19
    so what should I do, should I make to separate apps?
     
  20. Moderator

    dejo

    Staff Member

    #20
    No, just one version. If the camera is not supported, don't show the camera button. It's that simple.
     
  21. macrumors 65816

    uaecasher

    #21
    aren't that what we where doing lol :)?
     
  22. Moderator

    dejo

    Staff Member

    #22
    Exactly!
     
  23. macrumors 65816

    uaecasher

    #23
    I tired the app with my iPhone now, and when I press the library button, nothing happens.
     
  24. Moderator

    dejo

    Staff Member

    #24
    To what IBAction is the library button connected?
     
  25. macrumors 65816

    uaecasher

    #25
    grabImage
     

Share This Page