Friday, May 07, 2010

How to read files in Cocoa (mac os x and iphone)

We offen need read some files from a zip package. What can we do to read these files from a zip file without unzip it, and can we it simple as load resourse file using NSBundle.

There are many libraries can read zip format, the easiest library is zip-framework (http://code.google.com/p/zip-framework/). It can be used for iphone app.

Here is a tutorial:

1 Download the source from http://code.google.com/p/zip-framework/ . Add file ZipArchive.h ZipArchive.m ZipArchive+PrivateAPI.h ZipStructure.h to our project.

2 zip-framework is using library libz.dylib, so we must add libz.dylib to our project.

3 Here is the code, it is very simple:

ZipArchive *zip = [[ZipArchive alloc] initWithFile:@"test.zip"];
NSEnumerator *entries = [[zip entries] objectEnumerator];

id entryName;
while ((entryName = [entries nextObject]) != nil) {
[files addObject:entryName];
NSLog(@"%@",entryName);
}

//log all file name and path in the zip package

char buf[512];
int total_read = 0, len = 0, res = 0;
NSMutableData *filedata=[NSMutableData alloc];
FILE *largerFile = [zip entryNamed:@"pathto/imgname.JPG"];
if (largerFile != nil) {
while ((len = fread(buf, sizeof(char), 512, largerFile)) > 0) {
[filedata appendBytes:buf length:len];
total_read += len;
}
}
UIImage *img=[[UIImage alloc]initWithData:filedata];

// read image file pathto/imgname.JPG from zip package

Wednesday, April 21, 2010

Some questions about chinese internet

A report ask me some questions about chinese internet. Here is his questions and my answers.

1: Is censorship getting worse in China?

Yes.
The censorship really getting worse, many years ago, The "officer" will call your phone, ask you to delete some article in 1 day , or in some hours, it was all a means of censorship in that years. China Government didn't close websites or companies.
But in 2009, many websites be closed. The officer order IDC close many servers without owners allow.(the owner means website's webmaster or company)
Now, they also delete articles, and they try to control opinion direction. For example, The "officer" will tell website, what's should be header, what's must not show in homepage.

2: Are activists using Web 2.0 effectively?

No.
Many activists can't known what means web 2.0. They can't understand the read/write web. In there mind, web is just another newspaper. They write, others read, that's all. They did few interactive to others.
Some activist has got improvement, for example, Ai Weiwei , he become a power twitter user now.

3: Can the Chinese government beat Web 2.0 activism?

Maybe.
In china, run a website startup is in danger. Government tries to close any new interactive website , even a guestbook. But more and more people known how to use vpn/tor/ssh/... to avoid GFW.

If china government stop all internet, this happened in xinjiang, or they use QOS like Iran, they can beat web 2.0, they can beat internet. Otherwise I don't think they can beat web 2.0 in worldwide.For example, You can find more and more chinese twitter user.

4: What should US companies, and Google, do?

Nothing but support new tech, new product.
For example, TOR is a great tools for chinese. If more big company can support TOR (or other project like this), it will be a great help.

Wednesday, April 07, 2010

Why I think that iPhone/ipad is better than Android

Jack, my friend, helped me to buy a iPad yesterday. I am lucky, I can expire iPad earlier than most people. In china, many peoples can't understand apple at all. In their minds, Apple products means expensive, looks good but terrible in use. In fact, they hadn't use any one apple product ever.

December, 2001, Apple releases iPod. It is "just" a mp3 player. But it is a milestone for mobile computing device. Many years ago, Apple had tried send computer to every home and every desks, but they had failed. Microsoft (the wintel) have accomplished this mission. Now, most desktop computers are running windows.

Nowadays, mobile computing is beginning. The change start from mobile device manufacturers. Several years ago, mobile phone such as Palm and Nokia is mainstream products in the market. Microsoft keep on optimize their mobile OS, which named winCE. Many people worried microsoft will control all market, just they have done on desktop pc. At that time, few people notice what Apple was doing. Apple had entered mobile device market with the music walkman. It is really a great point, the total unit-in-use of music walkman may greater than the mobile phone.

2007, Apple releases ipod touch, the war is over. Sony, Microsoft, Nokia... no one of them can make things better. YES, iTouch is not a perfect product , but there are many disadvantages of other.

As a developer, I have tried many mobile device, include Android. Unfortunately, iPhone/touch is still the best friendly product for the developer.

The usability of a product is nothing to do with it base on a close system or an open system. Android, although an open system, cannot offer much value to both developers or end-users. Apple platform is the best choice for both developers and end-users, recently.

Here is my opinion:

1 For end-users, Apple products have a smoothly experience, but Andorid just the reverse. (For example, there are too many keys on android mobile, It is a puzzle)

2 For end-users, they can get many high quality applications from appstore. Iphone apps are more valuable than android apps, both free apps or commerce apps.

3 For end-users, iphone's price is 30% higher than android mobile(nexus one or HTC hero). It's not important to user at all.

4 For the developer, They can build more apps for iPhone in the same time. For Android platform, the compatibility is a difficult problem, because there are too many different Android mobile types.

5 For the developer, appstore include the reseller, the payment agent... Apple takes only 30% of revenue, It's valuable. In the share software market, a payment agent will take 20% of revenue at least, then you must pay for download sites, advertising...

6 For the developer, Maybe Android will become the king of consumer electronics market. It's mean nothing to me. I don't want to work for a consumer electronics company. But I will build some funny apps for iPad, in my spare time.

7 For small business users, they don't care about close or open system. They don't care about the license price even. What they are concern is the quality of the app. A killer app can provide an important niche market for a platform. I have found many killer apps for iphone, but none for android. For example, A GPS navigator user don't known the map base on winCE or Android.

8 For big companies, Linux will give them more freedom than Android.

9 For everyone, It is not the right time to dive into Android now. Although Android may have a bright future.

I will develop something for iPad. I'm sure iPad will show its quality in education and multi-media market. IPad can be used in many places, replace desktop computers. It's an economic choice.

We have compare Android with apple, but poor symbian need not be compared. Nokia is far away from the mobile computing market.

Saturday, March 06, 2010

How to Fix Quicksilver trigger Save Problems?

Quicksilver is a great application for Mac OS X. I strongly suggest every Mac users install it, and you can found many tutorial video on youtube.

My friend ask me why the options can't be saved after he adds some tigger. When he quit Quicksilver, every configrations lost. I try to add s
ome new tigger on my Quicksilver and quit, reopen, then them really disappeared. It is strange. I want to find out what's happened, I get code from them svn repository.

Then, I found a method named writeTriggers in QSTriggerCenter.m.

Quicksilver/Code-QuickStepCore/QSTriggerCenter.m

line:144

- (void)writeTriggers {
[self performSelector:@selector(writeTriggersNow) withObject:nil afterDelay:10.0 extend:YES];
}

Noticed the argument afterDelay, the value had been set to 10.0. This means it will be done after 10 second. There is only a few data need be saved, it needn't any delay. So I change this value to 0.

Now the code looks like:

[self performSelector:@selector(writeTriggersNow) withObject:nil afterDelay:0.0 extend:YES];

Build it by XCode, the copy Quicksilver.app/Contents/PlugIns/ from your old Quicksilver.app to our new release application.

It worked!

hello world!

Just another english blog. :)