您的位置:首页 > 编程语言

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

2010-08-19 13:31 357 查看
如果您的 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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: