激活 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;
}
-(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;
}
相关文章推荐
- 激活 iPhone通过 GPRS 连接服务器功能的代码--这个问题是很早以前的了 怀旧吧 早已解决了
- 【C#】Windows Mobile 通过代码设置GPRS连接
- 通过python代码远程连接服务器进行操作之paramiko模块
- 通过代码认识openstack 环境中连接到rabbit服务器
- 代码笔记 | ajax实现服务器与浏览器长连接的功能
- 【C#】Windows Mobile 通过代码设置GPRS连接,设置网络与接入点
- 通过连接服务器,得到本机连接的ip地址
- Hive:用Java代码通过JDBC连接Hiveserver
- Python通过Django实现用户注册和邮箱验证功能代码
- 用Java代码通过JDBC连接Hiveserver2
- 实现 iPhone 电子书的分页显示功能的代码
- Android通过webservice连接SQLServer 详细教程(数据库+服务器+客户端)
- 通过secureCRT远程连接服务器后安装mysql
- php通过SSH连接服务器并远程保存文件
- iPhone升级 “软件更新服务器不可连接”的解决办法
- 故障代码0xC004F074,系统与KMS服务器之间激活失败的解决办法
- 小程序通过apache服务器利用php连接mySQL
- gprs连接成功以后,如何通过socket获取网页html内容(C#)