質問

-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSString *theXML = [[NSString alloc] initWithBytes: [myWebData mutableBytes] length:[myWebData length] encoding:NSUTF8StringEncoding];
    NSLog(@"%@",theXML);    
    [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;
}

asp.net Webサービスの応答にplistファイルに保存したい。

しかし、時々、応答が巨大なサイズになることがあります。このような状況では、接続は50,000バイトを超えるデータを受信しました。そして、NSStringをNSStringするとき-(null)を出力します。

この場合、Webサービスの応答をファイルに保存できません。

これに対する解決策は何ですか? NSStringの代替方法はありますか? (この目的のために)

役に立ちましたか?

解決

何かを保存したい場合、すでにバイトがあります: [myWebData mutableBytes]

他のヒント

これはモバイルデバイスです。覚えておいてください。メモリは非常に限られているため、500000バイトを超えるサイズを割り当てたいと言うと、私に赤い旗を投げます。これは、この設計の問題になるでしょう。

ファイルサイズが n を超える場合は、ストリーミングまたはチャンクアルゴリズムを検討してください。 Webサービスは、応答を妥当な(および既知の最大)サイズとデバイスの部分に分割し、受信時にファイルに書き込むことができますか?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top