iphone ios http 异步同步操作

以下大家友情支持一下:

做了一个产品,需要人气支持一下,android和iphone上91市场搜索#super junior粉丝团#,或者直接到页面下载http://m.ixingji.com/m.html?p=X16,大家帮忙捧捧场。


同步

            NSString* urlString = [URLMake makePrepareUploadVideo:[AccountInfo getAccountInfo].uid 
                                                            token:[AccountInfo getAccountInfo].token
                                                         folderid:@"-1"
                                                         filepath:[self getUploadServerRelativePath:item]
                                                             sha1:self.sha1
                                                             size:[videoFileOp fileSize]
                                                        upchannel:@"2"
                                                         tryTimes:reTryTimes
                                                         filename:filename
                                                            intro:item.uploadFile.description
                                                           suffix:ext 
                                                        timestamp:item.uploadFile.createTime
                                                         latitude:item.uploadFile.latitude
                                                        longitude:item.uploadFile.longitude];
            
            //[videoFileOp release];
            ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:urlString]];
            [request startSynchronous];
            if( [request responseStatusCode] == 403 ){               
                ret = NO;
            }else{
                NSError *error = [request error];
                if (!error) {
                    NSData *data = [request responseData];
                    if (data && [JsonParser checkJsonResult:data] == 200) {
                        ret = [self parsePrepareUploadXml:data uploadItem:item];
                        
                        if (!ret) {
                            if (item.uploadStatus == kUploadStatusUploadSpaceNotEnough) {
                                ret = NO;
                            }else if (item.uploadStatus == kUploadStatusUploadHadUploaded){
                                ret = NO;
                                DLog(@"文件已经上传过, id=%@", item.uploadFile.fid);
                                item.uploadCompleted = YES; 
                            }
                        }
                        
                    }
                }
            }



异步

-(void)downloadFiles:(BOOL)update 
{    
    NSString *url = nil;
    NSDictionary* dictionary = nil;
    if (update) {
        url = [URLMake makeHotBackGirlUrl:0 getNum:MAX_GETLIST_NUM uid:[AccountInfo getAccountInfo].uid token:[AccountInfo getAccountInfo].token];
        dictionary = [NSDictionary dictionaryWithObjectsAndKeys:ft_BeautyGirlListJson, ft_Key, (update?@"update":@"more")
                      , @"updateType",nil];
    }else {//如果不是更新则接着最后一页去获取
        //BackGirlInfo *girlInfo = [self.resultList lastObject];
        url = [URLMake makeHotBackGirlUrl:self.resultList.count getNum:MAX_GETLIST_NUM uid:[AccountInfo getAccountInfo].uid
                                    token:[AccountInfo getAccountInfo].token];
        dictionary = [NSDictionary dictionaryWithObjectsAndKeys:ft_BeautyGirlListJson, ft_Key, (update?@"update":@"more")
                      , @"updateType",nil];
    }
    [self requestDataFromURL:url userInfo:dictionary];
}


- (void)requestFinished:(ASIHTTPRequest *)request
{
    NSString *dataType = [request.userInfo objectForKey:ft_Key];
    NSData* data = [request responseData];
    if (data.length > 0) {
        if ([dataType isEqualToString:ft_BeautyGirlListJson]) {
            BackGirlListParser *backGirlListParser = [[BackGirlListParser alloc] initWithData:data];
            if ([backGirlListParser parser]){
                if ([[request.userInfo objectForKey:@"updateType"] isEqualToString:@"update"]) {
                    self.resultList = backGirlListParser.resultList;
                    
                    NSString *path = path = [CachePathMake makeMainBeautyCachePath];
                    [CommonFun createDirectoryIfNeeded:path];
                    [data writeToFile:path atomically:YES];
                }else{
                    [self mergeResultList:backGirlListParser.resultList];
                }
                [self showMoreFooterView:backGirlListParser.resultList.count >= MAX_GETLIST_NUM?YES:NO];
                if(backGirlListParser.resultList.count > 0){
                    [self initQueenGirlPhoto];
                    [[self getTargetTableView] reloadData];
                }
                [self doneLoadingTableViewHeaderData];
            }else{
                [self doneLoadingTableViewHeaderData];
            }
            [backGirlListParser release];
        }else {
            [super requestFinished:request];
        }
    } 
}



你可能感兴趣的:(iphone ios http 异步同步操作)