Categories
Recent Posts

Posts Tagged ‘iPhone’

iPhone开发中内存的合理使用

内存管理

iPhone 开发过程中,内存的使用至关重要。不但要合理分配使用内存,还要注意内存泄露的问题, 因为内存泄露会导致程序由于内存不足而崩溃。根据个人开发的经验来看,在开发iPhone程序的过程中,关于内存的问题需要注意以下几点:

  1. 内存分配、释放成对出现
    使用 alloc 分配的内存对象需要在用完后 调用release释放
  2. 注意copy,retain,assign操作符的区别
    copy, retain操作符赋值的对象和alloc一样,需要release释放,否则会导致内存泄露
    assign 操作符的含义是将对象指向另一对象, 两者指向的是同一内存对象,无需调用release释放
  3. Read the rest of this entry »

关于iPhone开发库引用的问题

最近的项目用到了著名的Three20界面库, 程序发布完成结果背Apple拒绝,理由是使用了Private APIs, 没话说,肯定是Three20的问题。

于是获取最新代码,编译之后对可执行文件进行扫描确认没有Private APIs被调用了之后再build最终版本以提交App Store, 不知道是哪根筋不对突然觉得是否应该在真机上编译个release版本再提交,不然又要等若干天,万一被打回又得耽误功夫。 Read the rest of this entry »

iPhone开发中的问题整理(一)

看到很刚开始开发iPhone软件的朋友问很多问题,其实同样的问题我也碰到过, 所以抽时间把能想到的或者碰到的问题汇总一下, 一来可以给自己做个备忘也可以和朋友们分享探讨。

1. iPhone SDK 开发能不能使用C / C++ 语言?

Answer: iPhone SDK的开发的基础框架是基于cocoa库的, Objective-C 是cocoa的开发语言, 但基于Objective-C的特性,在iPhone程序中可以使用C/C++进行功能开发以及使用第三方C/C++库。 Read the rest of this entry »

ZipArchive has been updated to version 1.1 (更新至1.1版)

ZipArchive is a wrapper class to compress and uncompress zip files for Objective-C and cocoa use. It’s developed based on minizip and zlib.  The latest version is 1.1, new feature includes :

✩ create password protected zip files

✩ unzip password protected zip files

To obtain the new version up to date, please visit the project website http://code.google.com/p/ziparchive/

ZipArchive 是基于minizip和zlib的Objective-C 类, 用于创建和解压zip格式的压缩文件, 最新版本为1.1, 新增功能如下:

✩ 创建有密码保护的zip文件

✩ 解压有密码保护的zip文件

为了保证获取最新的版本, 请访问该项目网页 http://code.google.com/p/ziparchive/

Create custom checkbox style button for iPhone

Recently, I got a task to develop an application for iPhone. In the application,  there are some optional choices for user to decide further processes. The first idea jumps out from my head is something like button with a checkbox just the same as other desktop platforms, but unfortunately, iPhone SDK doesn’t provide such view. The only official choice is the ON|OFF switch view,  but it really can’t represent the actually meaning of the options. So comes out the idea of writing  custom checkbox style button.

It’s really easy to implement. What we need is two images which are statuses for check and uncheck.  Here are the runtime screenshots:

checkbutton uncheckbutton

The class  for Checkbox button  is CheckButton,  it’s inherited from UIButton,  look at the declaration:

1
2
3
4
5
6
7
8
9
10
#import 
 
@interface CheckButton : UIButton {
	BOOL		_checked;
}
 
@property (nonatomic, setter=setChecked) BOOL checked;
 
-(void) setChecked:(BOOL) check;
@end

Implementation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#import "CheckButton.h"
 
@implementation CheckButton
@synthesize checked = _checked;
 
-(id) init
{
	if( self=[super init] )
	{
		self.checked = NO;
		[self addTarget:self action:@selector(OnCheck:) forControlEvents:UIControlEventTouchUpInside];
	}
	return self;
}
 
-(void) awakeFromNib
{
	self.checked = NO;
	[self addTarget:self action:@selector(OnCheck:) forControlEvents:UIControlEventTouchUpInside];
}
 
-(void) dealloc
{
	[super dealloc];
}
 
-(void) setChecked:(BOOL) check
{
	_checked = check;
	if( _checked )
	{
		UIImage* img = [UIImage imageNamed:@"check.png"];
		[self setImage:img forState:UIControlStateNormal];
	}
	else
	{
		UIImage* img = [UIImage imageNamed:@"uncheck.png"];
		[self setImage:img forState:UIControlStateNormal];
	}
}
 
-(void) OnCheck:(id) sender
{
	self.checked = !_checked;
}
 
@end

To use the class, import the header where contains the button, and declare a IBOutlet with type of “CheckButton”, and connect the IBOutlet in InterfaceBuilder to the member as shown below:
import

This is simple but exactly meet my requirement. Of course, someone wants to include title text of the button within the button class,  it’s sure to be easy to do :)

Here is the sample project zip file.

免费的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配置

  • 选择 L2TP
  • 描述: HotspotShield
  • 服务器: 64.55.144.10
  • 帐号: 73582v (这是第一步生成的)
  • RSA SecurID: OFF
  • 密码: 73582v(这是第一步生成的)
  • 密钥: password (这里不是生成的密码,就是password)
  • 发送全部流量: ON
  • 3. 点击”存储“ 后,返回 设置->Wi-Fi 开启WiFi网络

    4. 打开 网络->VPN 启动VPN 服务,系统会自动链接验证vpn帐号,如果状态为”已连接“表示连接成功,就可以翻墙访问App Store和一些黑名单之中的网站了