//
// CMBCMallMessageEngine.h
//
//
// Created by on 1/31/13.
// Copyright (c) 2013 P&C,PhoneYeah. All rights reserved.
//
#import<Foundation/Foundation.h>
@interface CMBCMallMessageEngine :NSObject <TTURLRequestDelegate>
{
TTURLRequest *_mallMessageDownLoadRequest;
TTURLRequest *_mallMessageUpDateRequest;
}
@property (nonatomic,retain)TTURLRequest *mallMessageDownLoadRequest;
@property (nonatomic,retain)TTURLRequest *mallMessageUpDateRequest;
-(void)cancleRequest;
-(void)sendDownLoadMallMessageRequest;
-(void)cancleDownLoadRequest;
-(void)sendUpDateMessageRequest;
-(void)cancleUpDateRequest;
@end
//
// CMBCMallMessageEngine.m
//
//
// Created by on 1/31/13.
// Copyright (c) 2013 P&C,PhoneYeah. All rights reserved.
//
#import"CMBCMallMessageEngine.h"
#import"CMBCMallPromptMessage.h"
@implementation CMBCMallMessageEngine
@synthesize mallMessageDownLoadRequest =_mallMessageDownLoadRequest;
@synthesize mallMessageUpDateRequest =_mallMessageUpDateRequest;
-(void)dealloc
{
[_mallMessageDownLoadRequestrelease];
[_mallMessageUpDateRequestrelease];
[superdealloc];
}
-(void)cancleRequest
{
[selfcancleDownLoadRequest];
[selfcancleUpDateRequest];
}
-(void)sendDownLoadMallMessageRequest
{
self.mallMessageDownLoadRequest = [TTURLRequestrequestWithURL:CMBC_DOWNLOAD_MESSAGE_URLdelegate:self];
[self.mallMessageDownLoadRequestsetHttpMethod:Request_HttpMethod_Get];
[self.mallMessageDownLoadRequestsetContentType:@"appliction/xml"];
TTURLXMLResponse *response = [[TTURLXMLResponsealloc]init];
self.mallMessageDownLoadRequest.response = response;
response.isRSSFeed =YES;//导致 xml root 只有一个
[response release];
[self.mallMessageDownLoadRequestsend];
}
-(void)cancleDownLoadRequest
{
if (_mallMessageDownLoadRequest && [_mallMessageDownLoadRequestisLoading])
{
[_mallMessageDownLoadRequestcancel];
}
}
-(void)sendUpDateMessageRequest
{
}
-(void)cancleUpDateRequest
{
if (_mallMessageUpDateRequest && [_mallMessageUpDateRequestisLoading])
{
[_mallMessageUpDateRequestcancel];
}
}
-(void)parserXMLResponse:(TTURLXMLResponse *)response
{
TTURLXMLResponse *mallmessageResponse = (TTURLXMLResponse *)response;
NSDictionary *mallmessageRoot = mallmessageResponse.rootObject;
NSDictionary *messagelist = [mallmessageRoot objectForKey:@"mesgLists"];
NSDictionary *messagel = [messagelist objectForKey:@"mesgList"];
NSArray *messagearray = [messagel objectForKey:@"mesg"];
//NSInteger arraycount = messagearray.count;
CMBCMallPromptMessage *mallPromptmessage = [[CMBCMallPromptMessagealloc]init];
for (id item in messagearray) {
NSString * messageId = [[item objectForKey:@"busiId"]objectForXMLNode];
// NSString *messageId = @"1001";
NSString *message = [[item objectForKey:@"busiText"]objectForXMLNode];
if ([messageId isEqualToString:@"1001"]) {
mallPromptmessage.cinemaTicketMessage = message;
}
else if([messageId isEqualToString:@"1002"])
{
mallPromptmessage.gameCardMessage = message;
}
else if([messageId isEqualToString:@"1003"])
{
mallPromptmessage.passengerTicketMessage = message;
}
else if([messageId isEqualToString:@"1004"])
{
mallPromptmessage.interMarketmessage = message;
}
}
[CMBCMallPromptMessagesaveMallPromptMessageToUserDefault:mallPromptmessage];
}
#pragma TTURLRequest delegate回调
-(void)request:(TTURLRequest *)request didFailLoadWithError:(NSError *)error
{
}
-(void)requestDidFinishLoad:(TTURLRequest *)request
{
if (request ==self.mallMessageDownLoadRequest) {
if ([request.response isKindOfClass:[TTURLXMLResponse class]]) {
//parserXML
[selfparserXMLResponse:request.response];
}
}
elseif (request ==self.mallMessageUpDateRequest)
{
}
}
@end