如果您的 iPhone应用里含有连接服务器的功能,也许会遇到这种问题:WiFi 环境下连接正常,但用 GPRS 不能直接连接。因为纯 C 的 socket不能激活 GPRS,而 Apple 自带的 API 可以。所以要使用 GPRS连接功能,必须在程序启动时要运行一下这段代码
-(void)activeGPRSThread
{
NSError*error;
NSURLResponse*response;
NSMutableURLRequest*request = [NSMutableURLRequest requestWithURL:[NSURLURLWithString:@"http://tj.apple.google.com/tj.gif"]];
[requestsetHTTPMethod:@"GET"];
NSData*reData;
NSString*strData;
reData= [NSURLConnection sendSynchronousRequest:requestreturningResponse:&responseerror:&error];
strData =[[NSString alloc] initWithData:reDataencoding:NSUTF8StringEncoding];
NSLog(@"%@",strData);
g_isGPRSThreadActive= NO;
}
-(void)activeGPRSThread
{
}