`

激活 iPhone通过 GPRS 连接服务器功能的代码

阅读更多

如果您的 iPhone 应用里含有连接服务器的功能,也许会遇到这种问题:WiFi 环境下连接正常,但用 GPRS 不能直接连接。因为纯 C 的 socket 不能激活 GPRS,而 Apple 自带的 API 可以。所以要使用 GPRS 连接功能,必须在程序启动时要运行一下这段代码

-(void)activeGPRSThread
{
    NSError *error;
    NSURLResponse *response;
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://tj.apple.google.com/tj.gif"]];
    [request setHTTPMethod:@"GET"];
    NSData* reData;
    NSString* strData;
    reData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];    
    strData    = [[NSString alloc] initWithData:reData encoding:NSUTF8StringEncoding];
    NSLog(@"%@",strData);
    g_isGPRSThreadActive = NO;
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics