PDA

View Full Version : two app versions




uaecasher
Dec 9, 2009, 04:17 AM
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



robbieduncan
Dec 9, 2009, 04:28 AM
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.

uaecasher
Dec 9, 2009, 04:50 AM
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.

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

robbieduncan
Dec 9, 2009, 04:55 AM
I'm not sure how this is done, any links for documentation or other tutorials, thanks in advance

It's right there in the UIImagePickerController (http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html#//apple_ref/occ/clm/UIImagePickerController/isSourceTypeAvailable:) documentation.

uaecasher
Dec 9, 2009, 06:18 AM
Ok I feel really noob right now :o I have disabled the action now but how can I remove the button it self from the view.

Thanks

dejo
Dec 9, 2009, 09:25 AM
[button removeFromSuperView];

uaecasher
Dec 9, 2009, 09:47 AM
[button removeFromSuperView];


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:




#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

dejo
Dec 9, 2009, 09:51 AM
I tired it now, but it removes the button after i selected the 1st one and chose the image from library
Then you need to move the removeFromSuperview call to a more appropriate place in the code.

uaecasher
Dec 9, 2009, 09:57 AM
Then you need to move the removeFromSuperview call to a more appropriate place in the code.

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

dejo
Dec 9, 2009, 10:02 AM
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
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.

uaecasher
Dec 9, 2009, 10:12 AM
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.

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.

dejo
Dec 9, 2009, 10:14 AM
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.
And when do you actually want the button to no longer appear? After the application (view) is loaded?

uaecasher
Dec 9, 2009, 10:16 AM
And when do you actually want the button to no longer appear? After the application (view) is loaded?

yeah

dejo
Dec 9, 2009, 10:20 AM
If only there was an instance method that let you know when a view Did Load... ;)

uaecasher
Dec 9, 2009, 10:31 AM
If only there was an instance method that let you know when a view Did Load... ;)


: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

robbieduncan
Dec 9, 2009, 10:32 AM
: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

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

dejo
Dec 9, 2009, 10:39 AM
:D thanks it works now, I don't know how i forgot about that LOL. Thanks again.
You're welcome. Don't forget to rely on the documentation, especially the Class References. They're there to help you.

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
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 CraigsHarvest Lite, 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.

uaecasher
Dec 9, 2009, 10:40 AM
There must be other apps out there that present different interfaces based on camera availability. Probably hundreds of them...

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

uaecasher
Dec 9, 2009, 10:42 AM
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 CraigsHarvest Lite, 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.

so what should I do, should I make to separate apps?

dejo
Dec 9, 2009, 10:43 AM
so what should I do, should I make to separate apps?
No, just one version. If the camera is not supported, don't show the camera button. It's that simple.

uaecasher
Dec 9, 2009, 10:48 AM
No, just one version. If the camera is not supported, don't show the camera button. It's that simple.

aren't that what we where doing lol :)?

dejo
Dec 9, 2009, 10:50 AM
aren't that what we where doing lol :)?
Exactly!

uaecasher
Dec 9, 2009, 02:29 PM
I tired the app with my iPhone now, and when I press the library button, nothing happens.

dejo
Dec 9, 2009, 02:34 PM
To what IBAction is the library button connected?

uaecasher
Dec 9, 2009, 02:35 PM
To what IBAction is the library button connected?

grabImage

dejo
Dec 9, 2009, 02:40 PM
Well, the "meat" of your code in grabImage only executes if UIImagePickerControllerSourceTypeCamera is not available (see the starting if).

uaecasher
Dec 9, 2009, 02:50 PM
Well, the "meat" of your code in grabImage only executes if UIImagePickerControllerSourceTypeCamera is not available (see the starting if).

LOL so I did the conditional the wrong way, ok let's see what I need to do is remove the conditional and then just add the remove button for the camera grab button if the device is an iPod?

well I did this and it worked for iPhone, have to test it on my ipod now.

By the way, my app is asking me for location services, how come? I didn't call any GPS API.

dejo
Dec 9, 2009, 03:10 PM
By the way, my app is asking me for location services, how come? I didn't call any GPS API.
Why does iPhone camera ask location? (http://forums.macrumors.com/showthread.php?t=528346)

uaecasher
Dec 9, 2009, 03:23 PM
Why does iPhone camera ask location? (http://forums.macrumors.com/showthread.php?t=528346)

xD forgot about that, thanks.

dejo
Dec 9, 2009, 03:27 PM
uaecasher, you seem awfully gung-ho about this stuff. Just a word of advice: usually you're better off relaxing a bit and looking for answers rather than asking questions. This forum best helps those who help themselves.