2013年11月11日月曜日

iOSでCFNetworkのTCPを使うとBAD_ACCESSエラーが発生する問題

iOS6.1では発生しなかったので、iOS7のエミュレータ、実機で下記のコードを入れて対応
//定義
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

- (void) stream: (NSStream *) theStream handleEvent: (NSStreamEvent) streamEvent
{
    NSData *data;
   
    switch (streamEvent)
    {
        case NSStreamEventOpenCompleted:
        {
   self.filesInfo = [NSMutableArray array];
            self.didOpenStream = YES;
            self.receivedData = [NSMutableData data];
        } break;
           
        case NSStreamEventHasBytesAvailable:
        {
            data = [self.streamInfo read: self];
           
            if (data)
            {
                [self.receivedData appendData: data];
            }
           
            else
            {
                InfoLog(@"Stream opened, but failed while trying to read from it.");
                [self.streamInfo streamError: self errorCode: kBRFTPClientCantReadStream];
            }
        }
        break;
           
        case NSStreamEventHasSpaceAvailable:
        {
           
        }
        break;
           
        case NSStreamEventErrorOccurred:
        {
            [self.streamInfo streamError: self errorCode: [BRRequestError errorCodeWithError: [theStream streamError]]];
            InfoLog(@"%@", self.error.message);
        }
        break;
           
        case NSStreamEventEndEncountered:
        {
            NSUInteger  offset = 0;
            CFIndex     parsedBytes;
            uint8_t *bytes = (uint8_t *)[self.receivedData bytes];
            int totalbytes = [self.receivedData length];
          
            do
            {
                CFDictionaryRef listingEntity = NULL;
               
                 parsedBytes = CFFTPCreateParsedResourceListing(NULL, &bytes[offset], totalbytes - offset, &listingEntity);
               
                if (parsedBytes > 0)
                {
                    if (listingEntity != NULL)
                    {
                        if (SYSTEM_VERSION_LESS_THAN(@"7.0"))
                        {
                            id date = [(__bridge NSDictionary *) listingEntity objectForKey: (id) kCFFTPResourceModDate];
                            if (CFGetRetainCount((__bridge CFTypeRef) date) >= 2)
                                CFRelease((__bridge CFTypeRef) date);
                        }
                        self.filesInfo = [self.filesInfo arrayByAddingObject: (__bridge_transfer NSDictionary *) listingEntity];
                    }
                    offset += parsedBytes;
                }
               
            } while (parsedBytes > 0);
            [self.streamInfo streamComplete: self];
        }
        break;
       
        default:
            break;
    }
}

2013年11月8日金曜日

asp.net json 400 bat requestについて(データサイズの大きいリクエスト)

Web.configの設定を見なおして対応

<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <system.web>
  <compilation targetFramework="4.0" />
 </system.web>
 <system.serviceModel>
  <!-- WCFがASP.NET環境で動くように -->
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
  <standardEndpoints>
   <webHttpEndpoint>
    <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </standardEndpoint>
   </webHttpEndpoint>
  </standardEndpoints>
 </system.serviceModel>
</configuration>