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];
        }
    } 
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值