我正在编写一个邮件客户端的iOS应用程序。由于一些限制,我必须使用EWS(Exchange Web服务)来处理邮箱。我所能做的就是向服务器发送 SOAP 请求以获取必要的信息。到目前为止,我已经设法使用SyncFolderItems操作获取每个文件夹中的邮件列表。之后,我使用GetItem(电子邮件)操作获取每个项目的详细信息。最后一个请求仅返回电子邮件附件 ID 和名称,而不返回其大小。但是我需要知道它们才能让用户决定是否下载它们。我如何获得此信息?
下面是代码,我在其中创建对服务器的 SOAP 请求。
+(NSString*) syncFolderItems:(NSString*)folderID :(NSString*) syncState
{
NSString * syncStateStr=@"<SyncState>%@</SyncState>";
if(syncState!=nil && ![syncState isEqualToString:@""])
{
syncStateStr=[NSString stringWithFormat:syncStateStr,syncState];
}
else
syncStateStr=@"";
NSString * request= @"<?xml version="1.0" encoding="utf-8"?>"
"<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">"
"<soap:Body>"
"<SyncFolderItems xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">"
"<ItemShape>"
"<t:BaseShape>IdOnly</t:BaseShape>"
"</ItemShape>"
"<SyncFolderId>"
"<t:FolderId Id="%@"/>"
"</SyncFolderId>"
"%@"
"<MaxChangesReturned>10</MaxChangesReturned>"
"</SyncFolderItems>"
"</soap:Body>"
"</soap:Envelope>";
return [NSString stringWithFormat:request, folderID,syncStateStr];
}
+(NSString*)getMailItemsDetails:(NSMutableArray*)items
{
NSString *request =
@"<?xml version="1.0" encoding="utf-8"?>"
"<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">"
"<soap:Body>"
"<GetItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">"
"<ItemShape>"
"<t:BaseShape>Default</t:BaseShape>"
"<t:IncludeMimeContent>false</t:IncludeMimeContent>"
"<t:AdditionalProperties>"
"<t:FieldURI FieldURI="item:Attachments"/>"
"</t:AdditionalProperties>"
"</ItemShape>"
"<ItemIds>"
"%@"
"</ItemIds>"
"</GetItem>"
"</soap:Body>"
"</soap:Envelope>";
NSString *itemIdTemplate = @"<t:ItemId Id="%@" />";
NSString *itemsIds = @"";
for(NSString *msgID in items)
{
NSString *itemId = [NSString stringWithFormat:itemIdTemplate, msgID];
itemsIds = [itemsIds stringByAppendingString:itemId];
}
return [NSString stringWithFormat:request, itemsIds];
}
我错过了什么吗?(可能是一些额外的属性?我必须使用不同的请求吗?EWS 请求可以这样的事情吗?如果没有,是否有一些解决方法可以解决问题?任何帮助将不胜感激。
Yarlik,据我说,大小应该由服务器发送。
不管怎样,让我看看有没有发现什么,一定要转发给你。
但是,您可以在代表中做一件事,即;
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
}
-(NSURLRequest *)connection:(NSURLConnection *)connection
willSendRequest:(NSURLRequest *)request
redirectResponse:(NSURLResponse *)response {
}
long long fileSize = [response expectedContentLength];
它会给你文件大小。