 |
 |
|
 |
12-24-2011, 08:20 AM
|
#1 (permalink)
|
|
Registered Member
Join Date: Nov 2010
Posts: 15
|
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
|
|
|
12-24-2011, 11:19 AM
|
#2 (permalink)
|
|
Registered Member
Join Date: Nov 2010
Posts: 15
|
nobody???
|
|
|
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
|
That was a really, really quick thread bump.
What was your question, anyway?
|
|
|
12-25-2011, 09:08 AM
|
#4 (permalink)
|
|
Registered Member
Join Date: Nov 2010
Posts: 15
|
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;
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» 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 |
|