遇到這個問題,我想通過凹凸發送的圖像,但磕碰API的最大塊爲256KB如何NSKeyedUnarchiver與多塊來自凹凸?
if([[NSKeyedArchiver archivedDataWithRootObject:self.selectedImg]length] > 262144)
{
int dlen = [[NSKeyedArchiver
archivedDataWithRootObject:self.selectedImg] length];
NSLog(@"Sending data: %i bytes in %d chunks",dlen,
(int)ceil(((float)dlen/262144.0f)));
for (int i=1; i <= (int)ceil(((float)dlen/262144.0f)); i++) {
int maxr=0;
if ((262144*i) > dlen) {
maxr = dlen-(262144*(i-1));
} else {
maxr = 262144;
}
NSData *moveChunk = [[NSKeyedArchiver
archivedDataWithRootObject:self.selectedImg]
subdataWithRange:NSMakeRange(262144*(i-1),maxr)];
NSLog(@"Sending Chunk: %d, %d bytes",i,[moveChunk length]);
[bumpObject sendData:moveChunk];
}
}
else
{
//Data is 254kb or under
NSData *moveChunk = [NSKeyedArchiver
archivedDataWithRootObject:self.selectedImg];
[bumpObject sendData:moveChunk];
}
我如何編譯所有的塊一起?
一直花費3小時,但解決不了。
爲什麼不將'[NSKeyedArchiver archivedDataWithRootObject:self.selectedImg]'的值賦給變量?我認爲創建一個數據對象在系統資源上可能並不是微不足道的......(另外,你爲什麼不直接使用'dlen/262144'?不管怎樣,整數分割都會被截斷)。 – samson 2012-04-15 10:22:41
這是發送數據,這很好。但我需要知道如何從設備的另一側恢復 – Desmond 2012-04-15 10:40:36
這很難以這種方式閱讀。 – samson 2012-04-15 10:45:12