Posts Tagged ‘iPhone’
免费的iPhone VPN服务
这几天开会,导致iPhone无法访问App Store, 找了几个代理服务器地址均未能解决问题, 于是想到了VPN。
第一个想到的就是HotSpot Shield, 在桌面系统经常用它来访问某些被莫名其妙的屏蔽的网站,但一直没想过它有iPhone版本, 于是上官方网站查找, 发现Hotspot Shield已然提供了免费的vpn 服务, 而且无需下载客户端, 只需要在线申请一个帐号,即可,操作非常简单,只需要4个步骤。
1. 在浏览器输入网址 http://www.hotspotshield.com/clientless/iphone/get_started.php, 点击 “Get Account ID”, 只是会看到用户帐户及密码
2. 确认WiFi是关闭的, 设置->WiFi
然后依次进入 设置-> 通用 -> 网络 -> VPN -> 添加VPN配置
3. 点击”存储“ 后,返回 设置->Wi-Fi 开启WiFi网络
4. 打开 网络->VPN 启动VPN 服务,系统会自动链接验证vpn帐号,如果状态为”已连接“表示连接成功,就可以翻墙访问App Store和一些黑名单之中的网站了
近期GFW发功了,好多网站不能访问
继前几周开始namecheap无法正常访问之后, 陆续有好几个实用性的网站均无法正常浏览, 相比之下namecheap算是好的, 起码还可以打开,无非是缺少一些css而已,页面略显凌乱但基本功能正常。 可是其他的几个网站比如iPhone的开发类论坛http://www.iphonedevsdk.com, 以及常用的代理网站flyproxy.com也默默的无法访问了。 是不是GFW再作怪呢? 答案是肯定的, ms最近也没有什么重大的会议要开, GFW为何在此时发功,实在让人费解。 再说这几个网站除了flyproxy.com之外都是技术类网站, 奈何也被GFW无情的封杀。。。
在自己的程序中实现Email功能
在iPhone上如果想在应用程序里发送邮件只能通过调用系统默认email客户端程序,使用mailto协议,具体方法为
1 | [[UIApplication sharedApplication] OpenURL:@"mailto:someone@web.com?subject=test email...">mailto:someone@web.com?subject=test email..."]; |
这种方式建档方便, 如果只是简单的发送文本完全可以胜任, 不过如果需要发送附件或者html格式化的信件,这种方法将无法实现,此时需要在自己的程序中实现email发送代码。 如果你不想自己去实现发送的代码,请看SKPSMTPMessage , 该项目是google上的开源项目,实现了iPhone平台通过SMTP发送email的功能, 你可以通过http://code.google.com/p/skpsmtpmessage 获得代码,加入自己的项目即可。
SKPSMTPMessage 的使用方法也很简单,只需要分配一个新的SKPSMTPMessage 对象,设置相应的字段即可,比如
1 2 3 4 5 6 7 8 9 10 | SKPSMTPMessage mailMsg = [[SKPSMTPMessage alloc] init]; mailMsg.fromEmail = @"mylogin@gmail.com"; mailMsg.toEmail = @"mylogin@gmail.com"; mailMsg.relayHost = @"smtp.gmail.com"; mailMsg.requiresAuth = YES; mailMsg.login = @"mylogin"; mailMsg.pass = @"mypassword"; mailMsg.subject = @"test message"; mailMsg.validateSSLChain = NO; // 只用于自验证 mailMsg.delegate = self; |
提取iPhone程序生成的数据文件
如果你想从iPhone中取出应用程序生成的数据文件, 一般来说有三个方法,
- 使用Jailbreak 版本的iPhone或者ipod touch,安装ssh , ftp或者其他手机软件都可以完成此项任务。 这是最省事最方便的办法,不过严格的说事非法的:)
- 如果程序是你自己写的, 那么在程序中加入upload上传代码,将数据文件上传到指定的服务器
- 如果你是开发人员,只需打开xcode的organizer 即可完成数据文件的提取
对于普通用户,尤其是国内的用户来说,基本上都使用的是Jailbreak版本的水货机, 所以基本上无此烦恼。 而对于开发人员来说,常常需要知道自己的程序在真机上运行的情况以及生成的文件是否是正确的, 毕竟模拟器和真机还是有区别的, 所以第三种办法是最合适的。操作起来很简单。 只需将iPhone连接到电脑上, 打开xcode, 在windows 菜单下选择 Organizer , 然后在左侧选择自己的iPhone标示,在右边的application项中找到需要的程序, 如图

点击左侧小箭头,就会看见Application Data了, 这时只需点击右侧小三角形,就可以将数据文件下载到自己的电脑上了。
Objective-C class for zip/unzip zip format files
This is a simple class for compressing and extracting files. It works depend on minizip, which is a open source zip format library. And it’s included in the attachment.
The major class name is ZipArchive, it’s easy to use, you can declare a instance and call initialize functions, and then call addFileToZip or UnzipFileTo to finish compression or uncompression.
The code below shows you how to use it.
To create and add files to a zip
1 2 3 4 5 6 7 | BOOL ret = [zip CreateZipFile2:l_zipfile]; ret = [zip addFileToZip:l_photo newname:@"photo.jpg"]; if( ![zip CloseZipFile2] ) { l_zipfile = @""; } [zip release]; |
Extract files in a zip file to special directory, if the directory does not exist, the class will create it automatically. also if you pass ‘overWrite’ as ‘YES’ it will overwrite files already exist. You can also implement the methods of ZipArchiveDelegate to give more choices for overwriting.
1 2 3 4 5 6 7 8 9 10 11 | ZipArchive* za = [[ZipArchive alloc] init]; if( [za UnzipOpenFile:@"/Volumes/data/testfolder/Archive.zip"] ) { BOOL ret = [za UnzipFileTo:@"/Volumes/data/testfolder/extract" overWrite:YES]; if( NO==ret ) { } [za UnzipCloseFile]; } [za release]; |
iPhone表格中划动删除单元格
iPhone上的程序很多用表格UITableView来显示数据、做布局等。 当用UITableView显示数据是经常会需要删除、插入数据条目。 SDK提供两种删除UITableViewCell的方法
- 设置整个表格为编辑模式,如果没有做其他编辑风格(editing style),就会在每个单元格左面有一个圆形红色删除按钮,点击该按钮会在右边显示“Delete”按钮
- 在单元格上划动,会在划动的单元格右边显示“Delete”按钮, 这是SDK提供的快捷删除单元格的方法, 官方说法是 swipe to delete
要完成删除的动作必须在delegate中实现这个方法
1 2 3 | - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { } |
当点击“Delete” 删除按钮是会发送该消息, 在此可以处理删除。 此外如果想在删除按钮显示前以及删除动作完成后调整布局, 可以在delegate中实现下面两个方法
1 2 3 4 5 6 7 8 | // - (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath { } // - (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath { } |
需要注意的是,如果表格是在UIViewController里并且table的delegate是ViewController, 那么table必须是viewcontroller的view,而不是能是viewController 的view的一个子视图,比如在UIViewController的loadView实现中,以往会这么写
1 2 3 4 5 6 7 8 9 10 | -(void) loadView { UIView* contentView = [[UIView alloc] initWithFrame:...]; self.view = contentView; [contentView release]; tableView = [[UITableView alloc] initWithFrame:...]; // 初始化表格 [self.view addSubView: tableView]; } |
如果这样写,划动的时候就不会触发willBeginEditingRowAtIndexPath,必须这样写: self.view = tableView 才能触发willBeginEditingRowAtIndexPath。