0
NSString *mediaType = info [UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
    NSURL * URL = [NSURL URLWithString:[BGMakeURL URLForUploadImage]];
    UIImage * image = info[UIImagePickerControllerEditedImage];
    if(!image)
    {
        image= info[UIImagePickerControllerOriginalImage];
    }
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];

    parameters [@"__VIEWSTATE"]=@"/wEPDwUKMTQxNzIxMTc0MQ9kFgICAw8WAh4HZW5jdHlwZQUTbXVsdGlwYXJ0L2Zvcm0tZGF0YWRkpPnRKFYg9pwczRd4Lr3SFyeNR3bJtDpNqNyMm9qs/4g=";
    parameters [@"__EVENTVALIDATION"]=@"/wEWBgLE38oCAofc/4YFAuv/gd4CApahmrIJAuKeq6sMAu3ehcwDnwyRwRhgxmSADdcUMCfAUEl1cW8dliatCxOiAEYU8Jc=";
    parameters [@"Image"]=[FSNData withImage:image jpegQuality:.9 fileName:@"fileName"];




  FSNConnection *connection =
    [FSNConnection withUrl:URL
                    method:FSNRequestMethodPOST
                   headers:nil
                parameters:parameters
                parseBlock:nil
           completionBlock:^(FSNConnection * connection){
               id whatistheresult=connection.parseResult;
               PO(whatistheresult);
               [BGLoadingView toast:@"Image Uploaded"];
           }
             progressBlock:nil];
    [connection start];

就我现在而言,这不是同步的。如果我想要它同步呢?

4

1 回答 1

1

当然,但正确的方法取决于是否编译了 FSNetworking FSN_QUEUED_CONNECTIONS(从 GitHub 上的当前源代码判断)。假设它是,那么你会做这样的事情:

dispatch_semaphore_t sem = dispatch_semaphore_create(0);
FSNConnection *connection =
    [FSNConnection withUrl:URL
                    method:FSNRequestMethodPOST
                   headers:nil
                parameters:parameters
                parseBlock:nil
           completionBlock:^(FSNConnection * connection){
               dispatch_semaphore_signal(sem);
           }
             progressBlock:nil];
[connection start];
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER); // This will block until completion block is called
dispatch_release(sem);

如果它不是用你编译的,FSN_QUEUED_CONNECTIONS你需要旋转运行循环,像这样:

FSNConnection *connection =
    [FSNConnection withUrl:URL
                    method:FSNRequestMethodPOST
                   headers:nil
                parameters:parameters
                parseBlock:nil
           completionBlock:nil
             progressBlock:nil];
[connection start];

while (!connection.didComplete)
{
    CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, YES);
}

// Execution won't get here until the connection is complete.
于 2013-02-22T12:18:01.540 回答