2010年11月9日 星期二

Mac 安裝PHP XDebug


這幾天在用Mac開發php環境,光搞一個PHP debug環境有夠難搞的!後來發現其實要改的php.ini是要改/etc/php/ 下而不是/private/etc/ 接下來我就把流程分享給大家..

1.首先打開終端機,輸入$ sudo pecl install xdebug
2.接著輸入 $ sudo cp /etc/php.ini.default /etc/php.ini 複製一份至該路徑下

3.sudo vi /etc/php.ini且加入下面程式


[xdebug]
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so
xdebug.file_link_format="txmt://open?url=file://%f&line=%1"
xdebug.remote_enable = On
;xdebug.remote_handler = 'dbgp'
;xdebug.remote_handler = 'gdb'
;xdebug.remote_mode = jit
xdebug.remote_autostart = 1

4.重啓apache sudo apachectl stop 停止 sudo apachectl start 啓動


5.接著打開phpinfo若有看到下圖內容即表示安裝完成





接下來就看你要用Eclipse或MacGDBp瞜


我後來用MacGDBp 參考官網 http://www.bluestatic.org/software/macgdbp/

2010年10月22日 星期五

iphone開發,使用Three20 lib產生view的問題


最近小弟在進行iPhone App改版時遇到一個問題,搞了超久總算找到方式解決!
我也不知道我這個方式是不是很爛,遇到問題是這樣~
首先我因為要用Launcher效果,所以繼承了TTViewController,結果造成切換view時,view下方如圖1,紅色區塊的功能完全無法被點擊,所以去看了TTViewController.m之後,就想說我重新定義frame的長寬,結果沒想到就解決問題了...

@interface LauncherViewTestController : TTViewController {
TTLauncherView* _launcherView;
UIToolbar *first_toolbar;
UISearchBar *searchBar;
UILabel *title_label;
UIToolbar *states_toolbar;
}
@property (nonatomic,retain) UISearchBar *searchBar;
@property (nonatomic,retain) UIToolbar *first_toolbar;
@property (nonatomic,retain) UIToolbar *states_toolbar;
@property (nonatomic,retain) UILabel *title_label;

圖1

第二個問題如果一開始的view位置全部怪怪可以定義[window setCenter:CGPointMake(160, 259)];我在第一個view沒有使用xib方式賺寫,但其他view都採用xib,解決造成後面幾個view的內容全部網上,全部超過到statesbar去了,所以後來加入window setCenter 解決了~大家可以試試看摟

2010年8月21日 星期六

iPhone SQLite 新增一直失敗找到原因了




一開始的部份就不再說明教學了(是我太懶),讓大家參考這三個網站

1.iPhone Tutorial: Using SQLite3 database
http://ved-dimensions.blogspot.com/2009/03/iphone-development-sqlite3-populating.html

2.SQLite Tutorial - Saving images in the database
http://www.iphonesdkarticles.com/2009/02/sqlite-tutorial-saving-images-in.html

3.How do you insert an image into SQLite on the iPhone?
http://stackoverflow.com/questions/737443/how-do-you-insert-an-image-into-sqlite-on-the-iphone

今天為了要讓iPhone能透過讀取xml方式,取得更新的圖片url,得到url之後希望把圖片存到SQLite內,搞了超久一直失敗...
首先出現out of memory,光這個問題就找一個下午=.=,最後認真看到國外網友,它點出了db沒有正確讀到才會發生問題,下面這隻method就是連線成功的方式

- (void) getNewDBConnection{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"data.sqlite"];
BOOL success = [fileManager fileExistsAtPath:path];
if (sqlite3_open([path UTF8String], &database) == SQLITE_OK) {
NSLog(@"Database Successfully Opened :)");
} else {
NSLog(@"Error in opening database :(");
}
}

接下來連線成功之後遇到第二個error : no such table: item ,這個問題也讓人很吐血,明明在resource下有一個data.sqlite,我也用Firefox plugin 的SQLite Manager 建好table與欄位,為什麼會告訴我找不到item這個table呢。最後我把上面的method中的path路徑 NSlog出來才看到原來根本不是在resource下的data.sqlite,原來它存取的是/Users/Maccc/Library/Application Support/iPhone Simulator/4.0/Applications/87386C6E-CCBC-48BF-A121-CF9900D4E0C3/Documents/data.sqlite

insert 至db的method

- (void) addData:(UIImage*)image {
NSString *title=[NSString stringWithString:@"test"];
NSData *ImageData = UIImagePNGRepresentation(image);
NSInteger Imagelen = [ImageData length];
if(addStmt == nil) {
const char *sql = "insert into item(title,imageData) values(?,?)";
if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK)
NSLog(@"Error while creating add statement. '%s'", sqlite3_errmsg(database));
}

sqlite3_bind_text(addStmt, 1, [title UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_blob(addStmt, 2, [ImageData bytes], Imagelen, SQLITE_TRANSIENT);
if(SQLITE_DONE != sqlite3_step(addStmt))
NSLog(@"Error while inserting data. '%s'", sqlite3_errmsg(database));
else
sqlite3_last_insert_rowid(database);
//Reset the add statement.
sqlite3_reset(addStmt);
}

如果你有要轉換UImage為NSData可以用此method

- (UIImage*)loadImageFromUrl:(NSString*)url
{
NSURL *picUrl = [NSURL URLWithString:url];
NSData *picData = [NSData dataWithContentsOfURL:picUrl];
UIImage *image = [UIImage imageWithData:picData];
return image;
}

這樣你轉完後就可以存進db了..

2010年6月17日 星期四

iPhone Facebook SDK : no such file error


iPhone的Facebook SDK我相信有不少人在套用時候發生不少問題,光是把開發環境設定我就搞很久,按照官方的設定方式如圖匡起來的地方,根本一樣設定不好,所以你build的時候就會出現類似
FBSession.h no such file ......等等的error,解決方式如下
依照此流程:

在xcode的專案上按右鍵,選Get info,然後選Build tab,然後找到Search Paths下得Header Search Paths 把絕對路徑的Facebook路徑給他,
ex: Header Search Paths /Users/Mac/Documents/facebook-facebook-iphone-sdk-1059eb6/src/

這時候你在build應該就可以了

2010年6月10日 星期四

分享mobile開發上很棒的Framework

最近開發手機app時,常為了解決我們以關鍵字為主的服務,技術上會遇上許多問題,
所以找了很多Framework,希望未來可以再開發上更方便且又可以跨平台,所以跟大家分享一下瞜..
一個跨平台的Open Source Framework,可以支援iPhone, Android,Blackberry,Symbian (Sony Ericsson , Nokia , Qt) ,WindowMobile ,Palm,重點是寫他的code只要具備Html+Javascript+CSS就可以寫出手機平台的程式,真的非常的棒,你完全可以不需要會Object-c Java or C++ 就可以做出一個很棒UI的app,我今天還特別測試想說jQuery是否可以支援,我就去網路上找了一下,jQuery推出了一個以支援Mobile平台上的jQuery 稱 jQTouch,然後我就把jQTouch內的Demo code與JS and CSS檔丟進iPhone 的PhoneGap專案,沒想到執行之後居然可以跑,這就表示
連Ajax都可以支援,所以未來要開發除了iPhone平台之外的手持式平台都可以用這個來試水溫...

想挑戰他的威力就上網站看吧


附上執行的image