Archive for the 'how to' Category

how to – 用php抓取iTunes Store的搜索结果

星期六, 八月 6th, 2011

从iTunes Store中copy出来的链接无法直接在浏览器中打开,google之,有人已经用php+curl做了相关工作,只要在http header中加上一个参数即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function htmlForiTunesStoreURL($path)
// Download and return the HTML for an iTunes Store page at the given URL.
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $path);
 
    // The following header is what causes the server to think we are iTunes.app.
    // This header in particular is for the China Store.
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Apple-Store-Front: 143465-19,12'));
 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $html = curl_exec($ch);
 
    return trim($html);
}

其中X-Apple-Store-Front: 143465-19,12,143465是中国的iTunes Store代码,-19,12不知道什么意思,这是用截取http封包的工具截出来的,-19的位置是语言代码,但网上搜索不到中文代码是什么,也许就是19

以下是其他国家的代码:

United States 143441
Argentina 143505
Australia 143460
Belgium 143446
Brazil 143503
Canada 143455
Chile 143483
China 143465
Colombia 143501
Costa Rica 143495
Croatia 143494
Czech Republic 143489
Denmark 143458
Deutschland 143443
El Salvador 143506
Espana 143454
Finland 143447
France 143442
Greece 143448
Guatemala 143504
Hong Kong 143463
Hungary 143482
India 143467
Indonesia 143476
Ireland 143449
Israel 143491
Italia 143450
Korea 143466
Kuwait 143493
Lebanon 143497
Luxembourg 143451
Malaysia 143473
Mexico 143468
Nederland 143452
New Zealand 143461
Norway 143457
Osterreich 143445
Pakistan 143477
Panama 143485
Peru 143507
Phillipines 143474
Poland 143478
Portugal 143453
Qatar 143498
Romania 143487
Russia 143469
Saudi Arabia 143479
Schweitz/Suisse 143459
Singapore 143464
Slovakia 143496
Slovenia 143499
South Africa 143472
Sri Lanka 143486
Sweden 143456
Taiwan 143470
Thailand 143475
Turkey 143480
United Arab Emirates 143481
United Kingdom 143444
Venezuela 143502
Vietnam 143471
Japan 143462

关于第二位数字的解释
1: English
2: English (slightly different texts)
3: French
4: German
5: French (slightly different texts)

现在可以就可以正常获得数据了,如

1
2
3
echo htmlForiTunesStoreURL(
"http://ax.search.itunes.apple.com/WebObjects/MZSearch.woa/wa/advancedSearch?startIndex=180&entity=software&media=software&page=2&restrict=true&free=1&genreIndex=10"
);

How to – install Apache, PHP and Mysql on Mac XOS

星期三, 七月 27th, 2011

本文采用的方式是使用Mac OS X 10.5.6自带的Apache和PHP,安装MySQL的dmg版本,以下操作非特殊说明均以root用户在命令行下进行。

  启用root用户

  1.打开“目录实用工具”,它位于“应用程序”文件夹的“实用工具”文件夹中。

  2.点按锁图标以进行更改。您将需要输入管理员名称和密码。

  3.选取“编辑”>“启用 Root 用户”。

  4.为 root 用户输入安全密码,然后在“验证”栏再次输入它,最后点按“好”。

  启用Apache

  Mac OS X 10.5.6自带了Apache 2.2.9,直接在命令行运行apachectl start,Apache就搞定了。

  现在Apache的主目录就是/Libary/WebServer/Documents/,你可以在这目录里放置文件测试了。

  启用PHP

  Mac OS X 10.5.6自带了PHP 5.2.6,我们需要做的就是将PHP加入Apache中。

  修改/etc/apache2/httpd.conf中的

  #loadModule php5_module libexec/apache2/libphp5.so

  为

  loadModule php5_module libexec/apache2/libphp5.so然后将/etc/php.ini.default复制为/etc/php.ini。

  cp /etc/php.ini.default /etc/php.ini之后就可以按照自己的习惯修改php.ini的配置

  比如将error_reporting = E_ALL & ~E_NOTICE

  修改为

  error_reporting = E_ALL最后,重启Apache,可以在/Libary/WebServer/Documents/目录中建立个phpinfo.php来测试了。

  apachectl restart

安装Mysql

How to – build libcurl in xcode4 for iphone

星期二, 七月 26th, 2011

Download CURL source from:http://curl.haxx.se/download.html

1
2
3
4
5
6
7
tar -xvzf curl-7.21.2.tar.gz
cd curl-7.21.2
export CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-gcc-4.0.1
export CFLAGS="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk"
export LDFLAGS="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk -Wl,-syslibroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk"
export CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp
./configure --disable-shared --without-ssl --without-libssh2 --without-ca-bundle --without-ldap --disable-ldap --host=arm-apple-darwin10

By configuring with isysroot and syslibroot set the correct SDK, the CURL_SIZEOF_LONG and SIZEOF_LONG will get set to the correct value (4).
In Xcode, choose File->New Project->iOS->Library->Cocoa Touch Static Library.
Add->Existing Files (select curl’s “src” folder)
Add->Existing Files (select curl’s “lib” folder)
Remove “src/macos” folder from project. (Delete->Delete references)
Unselect Makefile and Makefile.inc checkboxes for target.
In “Build” tab search for OTHER_CFLAGS and add the following options:
-DHAVE_CONFIG_H -I/ca/dev/code/lib/curl/curl-latest/include -I/ca/dev/code/lib/curl/curl-latest/lib
Replace /ca/dev/code/lib/curl/curl-latest with the path at which you untarred the CURL source.
Build both Simulator/Release and Device/Release.
To make a universal library for both the simulator and the device, execute lipo from the command line of the Xcode project folder:

lipo -create build/Release-iphonesimulator/libcurl.a build/Release-iphoneos/libcurl.a -output libcurl.a
The last step is to add libCURL to your app by right-clicking (or option-clicking) Frameworks->Add->Add Existing Frameworks…->Other and choosing the libCURL.a file created by lipo.
In attachment You can find project and compiled lib.
the original resource – http://www.creativealgorithms.com/blog/content/building-libcurl-ios-42
Source code: Download

注意替换相应的路径
编译后的文件在
~/Library/Developer/Xcode/DerivedData/curl-aaqusppogmokgpgnggbgmkotqydh/Build/Products
(假设你的target名字是curl)
另外这里没写的
1.在search path里把curl/include加进去
2.修改build scheme,将build类型改成release

原文:http://blog.ideas-world.com/2011/03/14/building-libcurl-for-ios-4-2/(须翻墙)
还有一篇:http://blog.boreal-kiss.net/2011/03/15/how-to-create-universal-static-libraries-on-xcode-4/

UIPageControl例子

星期三, 七月 20th, 2011

http://www.edumobile.org/iphone/iphone-programming-tutorials/pagecontrol-example-in-iphone/
PageControlExample

how to – 自定义NavigationBar

星期五, 七月 8th, 2011

http://stackoverflow.com/questions/2259929/iphone-navigationbar-custom-background

https://discussions.apple.com/thread/1649012?threadID=1649012&tstart=0

Property List Programming Guide

星期四, 七月 7th, 2011

Property List Programming Guide

Supporting High-Resolution Screens

星期二, 七月 5th, 2011

http://developer.apple.com/library/ios/#DOCUMENTATION/2DDrawing/Conceptual/DrawingPrintingiOS/SupportingHiResScreens/SupportingHiResScreens.html#//apple_ref/doc/uid/TP40010156-CH15-SW1
My question

How to Deploy an Xcode App on an iPhone

星期四, 六月 16th, 2011

http://www.ehow.com/how_8409934_deploy-xcode-app-iphone.html

1
Sign up for the iOS Developer Program. The cost is $99 and you can enroll at the Apple Developers’ website. Indicate whether you wish to enroll as an individual or a company. If you enroll as an individual, your name will appear as the creator of the apps you distribute in the Apple App Store. Enroll as a company if you plan to add additional developers to your team or you want your company name to appear as the app creator. To enroll as a company, you need a legal company name, official company creation documents and the authority to sign legal documents for your company.

2
Obtain an iPhone Development Certificate from the iPhone Developer Program Portal to test your iPhone apps on your device. You’ll need a certificate for each device you plan to test on. You will need the unique identifier (UUID) for each device. Connect the device to your Mac and start Xcode to get the UUID. Select “Window” and then “Organizer” on the menu. The Organizer will display the UUID for your iPhone.

3
Generate a certificate-signing request for each device you want to use for testing. Go to the “Keychain Access” application in the Applications/Utilities folder. Once there, select the “Certificate Assistant” menu and choose the option to “Request a Certificate From a Certificate Authority.” Enter your email address. Select “Save to disk” followed by “Let me specify key pair information.” Click “Continue.” Choose a 2048-bit key size and RSA algorithm and save to a file.

4
Log in to the iOS Dev Center. When you reach the iPhone Developer Program Portal page, click “Launch Assistant.” Create an App ID for your app and click “Continue.” Assign a development device by entering its UUID. Submit the certificate-signing request to Apple.

5
Provide a description for your provisioning profile and click “Generate.” Once your provisioning profile has been created, you can download and install it on your device by dragging the provisioning profile and dropping it on the Xcode icon.

6
Navigate back to the iOS Developer Program Portal to download the development certificate and install it on your iPhone. Download and double-click the file to install it into a keychain. In the “Keychain Access” application on your Mac, select the login keychain and you’ll see a certificate for “iPhone Developer.” Click “Continue” in the Development Provisioning Assistant at the iOS Developer Program Portal to install your iPhone application with Xcode. In Xcode, choose “Active SDK” and select the OS version number of your device.

Deploy your app to your iPhone. With the app’s project open in Xcode, run the app. You will be prompted for permission to access your certificate. Click “Allow.” Your application should now be running on your iPhone.

How To – 在iphone模拟器中使用accelerometer

星期四, 六月 9th, 2011

万恶的苹果的iphone模拟器上竟然不支持用accelerometer,但拿到一本cocos2d的书的例子却净是用这个操作游戏的

google了一下,有位牛人做了一个模拟器,原理是把模拟器安装在ios设备上,通过udp发送accelerometer数据给xcode上的模拟器以达到在模拟器上debug的效果。
可以参考这个http://code.google.com/p/accelerometer-simulator/wiki/Home

mbp上自带svn还是挺强大的。。

在xcode4中添加cocos2d的工程模板

星期三, 六月 8th, 2011

http://www.cocos2d-iphone.org/archives/1412

用第一种方法可行