Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

How to pass additional parameters to ELCImagePickerController using Titaium

$
0
0
I have a titanium application with multi image picker using ELCImagePicker. I setup everything and it is functioning great. I would like to pass additional parameters to the module, however since the parameters are not global, it is giving me an error during usage. Titanium Code var my_module = require('jp.kray.ti.ELCImagePicker'); my_module.loadImagePicker({ iid:id, domain:'http://myhost/upload.php', success:function(data){ ... ObjectiveC Code - (void)loadImagePicker:(id)args { ENSURE_UI_THREAD(loadImagePicker,args); ENSURE_SINGLE_ARG_OR_NIL(args,NSDictionary); NSLog(@"Load ImagePicker\n"); if (args != nil) { // callbacks if ([args objectForKey:@"success"] != nil) { pickerSuccessCallback = [args objectForKey:@"success"]; ENSURE_TYPE_OR_NIL(pickerSuccessCallback,KrollCallback); [pickerSuccessCallback retain]; } if ([args objectForKey:@"cancel"] != nil) { pickerCancelCallback = [args objectForKey:@"cancel"]; ENSURE_TYPE_OR_NIL(pickerCancelCallback,KrollCallback); [pickerCancelCallback retain]; } NSString *uploadUrl = [TiUtils stringValue:[args objectForKey:@"domain"]]; NSString *iid = [TiUtils stringValue:[args objectForKey:@"iid"]]; } _albumController = [[ELCAlbumPickerController alloc] init]; ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initWithRootViewController:_albumController]; [_albumController setParent:elcPicker]; _albumController.assetFilter = kELCAlbumAllAssets; _albumController.cellHeight = 75; _albumController.titleForSelection = NSLocalizedString(@"Pick Something", @"Title for picking items"); [elcPicker setDelegate:self]; TiApp *tiApp = [TiApp app]; [tiApp showModalController:elcPicker animated:YES]; [elcPicker release]; } Problem Code in Controller - (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info { NSLog(@"success didFinish:\n"); if (pickerSuccessCallback != nil) { id listener = [[pickerSuccessCallback retain] autorelease]; NSMutableArray *images = [NSMutableArray array]; for (NSDictionary *dict in info) { UIImage *image = [dict objectForKey:UIImagePickerControllerOriginalImage]; //Activate the status bar spinner UIApplication* app = [UIApplication sharedApplication]; app.networkActivityIndicatorVisible = YES; //The image you want to upload represented in JPEG //NOTE: the 'selectedPhoto' needs to be replaced with the UIImage you'd like to upload NSData *imageData = UIImageJPEGRepresentation(image, 1); //NOTE: Change this to the upload URL you're posting to //NSString *uploadUrl = @"http://"+[NSString *domain]+"/upload.php"; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; //[request setURL:[NSURL URLWithString:uploadUrl]]; [request setURL:[NSURL URLWithString:@"http://localhost/upload.php"]]; [request setHTTPMethod:@"POST"]; NSMutableData *body = [NSMutableData data]; NSString *boundary = @"---------------------------14737809831466499882746641449"; NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]; [request addValue:contentType forHTTPHeaderField:@"Content-Type"]; //The file to upload [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"image\"; filename=\".jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[NSData dataWithData:imageData]]; [body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; // another text parameter [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"parameter2\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithString:iid] <---- Here ----> It can not find iid. I tried to declare a global variable and overwrite it using the loadImagePicker method but it still is complaining. Thank you

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>