Posts Tagged ‘iPhone’
如何使用.net实现iPhone和电脑之间的文件传输
最近太忙,工作医院两头跑,整个人有点分身乏术了。 所以老巢——这里也很少更新了。
言归正传, 现在iPhone越来越火了, 各种iPhone周边的应用需求也就越来越大。 AppStore更不必说,那是相当的火, 另外就是对iPhone进行管理的相关桌软件,像国内的91手机助手, QQ手机助手等都可以对iPhone的文件进行管理,国外的软件就更多的不计其数了。
其实, 这类软件的实现也不是非常难, 大多数都是通过调用Apple的动态库函数来实现iPhone和电脑的通信。常用的动态库包括MobileDevice.dll、CoreFoundary.dll等几个。 虽然都是apple自己提供的,但iTunes中并没有开放更多多的功能,比如直接往iPhone、iPad上拷贝文件,从iPad或者iPhone上直接拷贝文件到windows等。所以,我们可以通过apple提供的库函数来实现这样的需求。
常用的函数列表可以google搜索到,比如以下这些
static int AMDeviceNotificationSubscribe
static int AMDeviceConnect(void* device);static int AMDeviceDisconnect(void* device);
static int AMDeviceIsPaired(void* device);
static int AMDeviceValidatePairing(void* device);
static int AMDeviceStartSession(void* device);
static int AMDeviceStopSession(void* device);
static int AMDeviceGetConnectionID(void* device);
static int AMRestoreModeDeviceCreate
如果你熟悉.NET,可以看看开源代码Manzana。 manzana是iPhone交互通信的.net开发包,该开源项目可以在google code上找到http://code.google.com/p/manzana/。
其中, MobileDevice.cs是对CoreFoundary.dll和MobileDevice.dll的封装, iPhone.cs则是对iPhone处理事件的进一步封装。 首先要注册一个设备连接和断线的事件接收者,当iPhone或者iPad连接上电脑后会收到DeviceNotificationEvent,根据事件类型进行处理。 在项目下载页面中可以找到简单的UI界面实现了基本功能,也可以很好的理解其工作原理。 如果你也想开发一款类似的软件那么研究一下mazana将很有帮助。
使用manzana不但可以实现简单的iPhone和电脑之间的文件传输,还可以实现更复杂的功能,不过这些需要对manzana进行修改和改进才行。
iPhone开发中内存的合理使用

iPhone 开发过程中,内存的使用至关重要。不但要合理分配使用内存,还要注意内存泄露的问题, 因为内存泄露会导致程序由于内存不足而崩溃。根据个人开发的经验来看,在开发iPhone程序的过程中,关于内存的问题需要注意以下几点:
- 内存分配、释放成对出现
使用 alloc 分配的内存对象需要在用完后 调用release释放 - 注意copy,retain,assign操作符的区别
copy, retain操作符赋值的对象和alloc一样,需要release释放,否则会导致内存泄露
assign 操作符的含义是将对象指向另一对象, 两者指向的是同一内存对象,无需调用release释放
关于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:

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:

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