views:

190

answers:

0

I've built an app that runs in the background (jailbroken phone, Ver. 3.0/7A341) that checks my website every hour. When the device goes to sleep, I set a time to wake up if it stays asleep

My app wakes up fine, then tries to make a network connection, but no luck. I've tried what iphone-3g-connection-enabling recommends (NSURLConnection, [NSString stringWithContentsOfUrl ... ], etc.) but if I don't manually hit the home key, then slide to unlock, a network connection isn't made. With the manual slide to unlock, the connection is made no problem.

Since I'm running on a jailbroken phone, is there some other way to force a network connection without manual intervention? I've tried launching other applications (Safari, Mail client) but no luck.

This is what I'm doing on wakeup....

case kIOMessageSystemHasPoweredOn:
    NSDate *newDate = [NSDate date];
    newDate = [newDate addTimeInterval:2]; //wait a little bit

    NSTimer *wakeTime = [[NSTimer alloc] initWithFireDate:newDate 
            interval: 5 
            target:self 
            selector:@selector(connectToNetwork)
            userInfo:nil 
            repeats:NO];

    [[NSRunLoop currentRunLoop] addTimer:wakeTime forMode:NSDefaultRunLoopMode];


    [wakeTime release];


-(void) connectToNetwork
{  
    NSURL *u = [NSURL URLWithString:@"http://www.apple.com"]; //tried ip also
    NSString *translation = [[NSString alloc] initWithContentsOfURL:u];
    if( translation != NULL )
    {
        //We're Good
    }
    /* also tried
       [NSURLConnection sendSynchronousRequest...
       [[NSURLConnection alloc] initWithRequest...
       [NetworkController bringUpEdge ]
    */
    .........
}