Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-24-2011, 08:20 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 15
logan is on a distinguished road
Default good use of ASIHTTP ?

this is my code.it 's good or not because i try to get somes pictures from URL in background (asynchronous)?



Code:
if (![self queue]) {
			[self setQueue:[[[NSOperationQueue alloc] init] autorelease]];
		}
		
NSURL *url = [NSURL URLWithString:@"http://*******.php"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestDone:)];
[request setDidFailSelector:@selector(requestWentWrong:)];
[[self queue] addOperation:request]; //queue is an NSOperationQueue
	}
	

- (void)requestDone:(ASIHTTPRequest *)request{
    NSString *response = [request responseString];
     self.online = [response JSONValue];
    for(int i=0;i<[online count];i++)
            		{           			        			
            			NSDictionary *dict=[online objectAtIndex:i];
                  			
        NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
            			
            			
        NSString* pict =  [documentsPath stringByAppendingFormat:@"/%@_%@",[dict objectForKey:@"1"],[dict objectForKey:@"6"]]; 
            			
            			
        NSString* pseudoTof = [NSString stringWithFormat:@"%@_",[dict objectForKey:@"1"]];
            			
            			
        BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:pict];
            			
            			
        if (fileExists)	{
            				
            			
            			}else {
            										
            				
        if([pict rangeOfString:pseudoTof].location != NSNotFound) 
            					
            				{								
            					
        NSFileManager *fileManager = [NSFileManager defaultManager];
            					
        [fileManager removeItemAtPath:pict error:NULL];
            											
            				}
            				
            				
        else {
            									
            
            													
            				
  NSString *string=[dict objectForKey:@"5"];
            							
  	
        NSURL *finalURL = [NSURL URLWithString:[string stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];
            				
            				
        NSURL *url=[NSURL URLWithString:string];
            				
            				
            				
        UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL: finalURL]];
            				
            				
            				
            				
        NSData *data2 = [NSData dataWithData:UIImageJPEGRepresentation(image, 0.5)];//1.0f = 100% quality
            				
            				
        [data2 writeToFile:pict atomically:YES];
            									
            				
            			}
            			
            			
            		}				
            				
        [salonTbView reloadData];
            			
            				
            		
            	}
            	
            	- (void)requestWentWrong:(ASIHTTPRequest *)request
            	{
            		NSError *error = [request error];
            		NSLog(@"erreur %@",error);
            	}
thx for reading
logan is offline   Reply With Quote
Old 12-24-2011, 11:19 AM   #2 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 15
logan is on a distinguished road
Default

nobody???
logan is offline   Reply With Quote
Old 12-24-2011, 05:03 PM   #3 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
dljeffery is on a distinguished road
Default

That was a really, really quick thread bump.

What was your question, anyway?
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 12-25-2011, 09:08 AM   #4 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 15
logan is on a distinguished road
Default

hi

just want to know if it will be slow on the iphone.

so first i have to download pictures and put them in tableview like that

Code:
  
    // Configure the cell...
	
	dico = [self.pseudoOnline objectAtIndex:indexPath.row];
	cell.text =  [dico objectForKey:@"1"];
	cell.detailTextLabel.text = [dico objectForKey:@"2"];
	
	NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
	NSString* pict =  [documentsPath stringByAppendingFormat:@"/%@_%@",[dico objectForKey:@"1"],[dico objectForKey:@"6"]];
	
	
	
	BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:pict];
	
	cell.image = [UIImage imageWithContentsOfFile:pict];
	
	return cell;
logan is offline   Reply With Quote
Reply

Bookmarks

Tags
asihttprequest, asynchronous, iphone, xcode

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 393
13 members and 380 guests
7twenty7, AppsBlogger, Creativ, Dalia, David-T, Duncan C, HemiMG, heshiming, LunarMoon, Murphy, pbart, teebee74, Tomsky
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,915
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:51 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0