views:

41

answers:

2

Peace , my eXercice is to make the application connect , send and receive data to remote webserver and this is every 10 Secondes so idea goes to work with NSTimer and adding it into a runLoop , but the connection is established only once and then then ( in the next 10 seconds ) the app Crashes . Here is my Code , THANK YOU for HELPING .

#define HTTP_CONTACT_TIMEOUT 10.0
@implementation HTTPEXERCICEAppDelegate


@synthesize window;
@synthesize HttpConnTimer;

#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  


self->HttpConnTimer = 
[NSTimer scheduledTimerWithTimeInterval:HTTP_CONTACT_TIMEOUT target:self selector:@selector(Contact:) userInfo:NULL repeats:YES];

[[NSRunLoop mainRunLoop] addTimer:self->HttpConnTimer forMode:NSRunLoopCommonModes];

return YES;

 }


 -(void) Contact:(NSTimer*)ttimer { 

 NSAutoreleasePool *Pool = [[NSAutoreleasePool alloc] init];
 HTTP_Comm *HTTPClient = [[HTTP_Comm alloc] init];
 [HTTPClient CommunicateWith:@"http://someURL"];
 [HTTPClient release];
 [Pool release];
 }  
A: 

very suspicious place is

 HTTP_Comm *HTTPClient = [[HTTP_Comm alloc] init];
 [HTTPClient CommunicateWith:@"http://someURL"];
 [HTTPClient release];

are you sure you've retained HTTPClient in CommunicateWith:? It either should be retained or should not be used after that.

Also do not use together:

[NSTimer scheduledTimerWithTimeInterval:HTTP_CONTACT_TIMEOUT target:self selector:@selector(Contact:) userInfo:NULL repeats:YES];

[[NSRunLoop mainRunLoop] addTimer:self->HttpConnTimer forMode:NSRunLoopCommonModes];

because scheduledTimerWithTimeInterval... already added timer to runloop. Use only scheduledTimerWithTimeInterval... or timerWithTimeInterval... with addTimer...

Vladimir
Anyone can suggest and give helps ...its realy supposed to work..
Archer
A: 

I m receivding signal:"EXC_BAD_ACCESS" , trying to track out that error I m Having this :

0 0x02af9a93 in objc_msgSend 1 0x07336d00 in ?? 2 0x000045d6 in -[HTTP_Comm CommunicateWith:] at HTTP_Comm.m:36 3 0x00002808 in -[TorndAppDelegate Contact:] at TorndAppDelegate.m:52 4 0x00063c99 in NSFireTimer 5 0x028bfd43 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION 6 0x028c1384 in __CFRunLoopDoTimer 7 0x0281dd09 in __CFRunLoopRun 8 0x0281d280 in CFRunLoopRunSpecific 9 0x0281d1a1 in CFRunLoopRunInMode 10 0x02f992c8 in GSEventRunModal 11 0x02f9938d in GSEventRun 12 0x002dbb58 in UIApplicationMain 13 0x00002668 in main at main.m:14

Archer