开发者

What is the maximum length of NSString? Alternative to NSString - iPhone

-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSString *theXML = [[NSString alloc] initWithBytes: [myWebData mutableBytes] length:[myWebData length] encoding:NSUTF8StringEncoding];
    NSLog(@"%@",the开发者_如何学GoXML);    
    [self actualString:theXML 
            extractMyData:@"<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body><GetCategoryResponse xmlns=\"http://tempuri.org/\"><GetCategoryResult>"
            endingString:@"</GetCategoryResult></GetCategoryResponse></soap:Body></soap:Envelope>" 
            emptyString:@"<Prop_Category />"];
    [theXML writeToFile:[self GetMyFilePath] atomically:YES encoding:NSStringEncodingConversionAllowLossy error:nil];
    [theXML release];
}

-(NSArray*)actualString:(NSString*)theXML extractMyData:(NSString*)prefixString endingString:(NSString*)suffixString emptyString:(NSString*)noDataFromXMLString{
    // now here I want to extract data from string
    // from theXML
}

-(NSString*)GetMyFilePath{
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *documentDirectory=[paths objectAtIndex:0];
    NSString *pathToUserCopyofplist=[documentDirectory stringByAppendingPathComponent:@"myWebServiceData.plist"];
    NSLog(@"%@",pathToUserCopyofplist);
    return pathToUserCopyofplist;
}

I want to save to response of asp.net web service in a plist file.

But sometimes, when response may be in a huge size. In such situation connection has received data more then 50,000 bytes. And when I NSlogs NSString - it prints (null).

In this case I can't store web service response to the file.

What should be solution for this? Is there any alternate way of NSString? (for this purpose)


If you want to store something, you already have the bytes: [myWebData mutableBytes]


It's a mobile device, remember. Memory is extremely limited and when you say that you might want to allocate more than 500000 bytes, it throws a red flag for me. This is going to be an issue for you with this design.

Consider coming up with a streaming or chunk algorithm if the file size is over n. Maybe your web service can break the response up into parts of a reasonable (and known maximum) size and the device and write them to the file as it receives them?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜