2012年12月17日 星期一

iOS 開發筆記 - 使用 XCode Subprojects 與 Git Submodule

xocde_subproj


雖然 Objective C 的經驗不多,但漸漸地會想把一些共用的程式碼弄成 library 來使用,在加上 git 來管理,這時候就會想到 git submodule 的使用。原先以為把 xcode project 拖拉進來就可以了,後來發現這一切都只是幻想 XD 整體上的概念:編譯時要能找到(header search path),連結時要能找到(link binary)。原本以為拖拉其他 project 進來就能自動化搞動,最後發現還是要手動設定一些環境,所以就來筆記一下。


例如有 Base.xcodeproj 和 Test.xcodeproj,先把常用的程式碼都寫在 Base.xcodeproj:


建立 Xcode Project:


create_base_xcodeproj


新增 TARGETS -> Add Target:


add_target_static_lib


add_target_static_lib_name 


把想要編成 static library 的程式碼擺進 Compile Sources:


create_static_library


add_other_source


使用 git 管理(假設在 /tmp/base.git):


$ mkdir /tmp/base.git
$ cd /tmp/base.git
$ git init --bare
$ cd /path/Base
$ ls
Base  Base.xcodeproj  BaseLib
$ git init
Initialized empty Git repository in /path/Base/.git/
$ git remote add origin /tmp/base.git
$ git add .
$ git commit -am 'init'
$ git push origin master


在 Test.xcodeproj 裡使用 Base.xcodeproj:


建立 Test xcodeproj:


create_test_xcodeproj


使用 git 管理(假設在 /tmp/test.git):


$ mkdir /tmp/test.git
$ cd /tmp/test.git
$ git init --bare
$ cd /path/Test
$ ls
Test  Test.xcodeproj
$ git init
Initialized empty Git repository in /path/Test/.git/
$ git remote add origin /tmp/test.git
$ git add .
$ git commit -am 'init'
$ git push origin master


使用 git submodule 管理 Base library:


$ cd /path/Test
$ ls
Test  Test.xcodeproj
$ git submodule add /tmp/base.git libbase
Cloning into 'libbase'...
done.
$ ls -a
.   .git               Test  libbase
..  .gitmodules  Test.xcodeproj
$ cat .gitmodules
[submodule "libbase"]
  path = libbase
  url = /tmp/base.git
$ git commit -am 'add libbase'
[master 5f69c71] add libbase
  2 files changed, 4 insertions(+)
  create mode 100644 .gitmodules
  create mode 160000 libbase
$ git push origin master


設定 Text.xcodeproj:


拖拉 Base.xcodeproj 進來(從 /path/Test/libbase):


drag_base_xcodeproj


設定 Header Search (/path/Test/libbase):


add_header_search


header_search_path


設定 Other Linker Flags:


-all_load  (如果 library 中有 categories)


設定 Link Binary With Libraries:


link_binary


更新 git:


$ cd /path/Test
$ git add .
$ git commit -am 'add libbase'
$ git push origin master


如此一來,未來在取 Test 的時候,就可以這樣用:


$ git clone --recursive /tmp/test.git testxcode
Cloning into 'testxcode'...
done.
Submodule 'libbase' (/tmp/base.git) registered for path 'libbase'
Cloning into 'libbase'...
done.
Submodule path 'libbase': checked out '920380a7c727d7fb42e38e89bd2eac7a3d2ef72f'
$ ls -a testxcode
.     .git                Test               libbase
..    .gitmodules   Test.xcodeproj


此外,其他時候可能會需要以下指令:


$ git submodule update --init --recursive


iOS 開發筆記 - iOS 6 UIViewController shouldAutorotateToInterfaceOrientation 失效 (orientation bug?)

複習一下 UIViewCnotroller ,在一樣的程式碼,在 iOS 6 不能做 Device Autorotate ,測試了一下是之前用法使用 UIViewController 的方式要更新一下。


以前在 AppDelegate.m 中,使用 [self.windows addSubview:my.view]; 的用法,需更新為 [self.windows setRootViewController:my]; ,如此一來在 iOS 5 跟 iOS 6 都可以正常使用了。


AppDelegate.m:


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.

   UINavigationController *nav = [[UINavigationController alloc] init];

   [self.window setRootViewController:nav];
   //[self.window addSubview:nav.view];

   self.window.backgroundColor = [UIColor whiteColor];
   [self.window makeKeyAndVisible];
   return YES;
}


2012年12月6日 星期四

[MSN] 線上編輯、刪除、還原、匯出聯絡人清單


前陣子微軟公布之後要將 MSN 合併至 Skype 帳號,有點半放棄 MSN 吧?總之 Skype 已經可以提供使用 MSN 帳號登入了,為了在 Mobile (Android) 上可以使用官方的 MSN client,我就把 MSN 跟 Skype 整合了。然而,整合後一個禮拜左右,開始發現用 MSN 登入 Skype 時,看不到 MSN 聯絡人,甚至切換到 Windows XP 用 MSN 軟體登入,一樣也看不到聯絡人,開始產生聯絡人消失的奇怪 bug!雖然可以從其他地方找到聯絡人,但似乎不太方便。


幸運的,可以從 http://people.live.com/ 進去管理自己的 MSN 帳號,包括管理群組、刪除和還原聯絡人,最重要的則是有匯出功能,包括可以備份自己取的代稱等,實在便利。而 MSN 聯絡人不見得問題,則是去還原即可,需留意刪除的聯絡人只保留 30 天喔。


2012年11月26日 星期一

台灣免費網路電視清單 @ Mac OS X、iPad、iPhone

因為一些因素,需要免費的網路電視(直播電視)來解悶,一開始看到"壹電視"網路新聞台還滿黑皮的,只是看久了就發現台灣的新聞播報方式幾乎憂多於喜,看久了會不爽快,漸漸地又想找一些其他台來看看,最後才想起偉大的中華電信 hichannel 頻道,但 hichannel 多只能用 Windows 平台配 IE 瀏覽器 + Windows Media Player 才能觀看,頓時又讓人倒退幾步。


慶幸的找了一會兒,終於找到 iPad 版 XD 看來台灣廠商都對 iPad 比較有愛,像壹電視、Hinet Hichannel 部分頻道有支援 iPad (Safari瀏覽器),但在 Android 上,點開不是不支援,不然就是要用 Flash player (手機 Flash player 已經在 2012.08 月份被 Adboe 拋棄了),真不知該說什麼。


總結一下,免費的網路電視及頻道:



簡單來說,若你是用 Windows 作業系統,那網路上免費的正版網路電視都可以觀看(壹電視+hichannel),若你是用 iPad 的話,那有部分可以觀看(壹電視+部分hichanel,且必須先從hichannel ipad 版廣播進去,不能直接連[須有 http reference 的機制]),最後,若你是用 Mac OS X 系統,用 Safari 則可以透過 iPad 網頁可以看的節目。至於 Linux 的系統就沒研究了 XD 不知裝一下 Safari 瀏覽器行不行。我個人是新聞播膩了,就播播東森亞洲衛視,偶爾有娛樂性質。


至於其他非正統版權的來源,則可以逛逛 justin.tv -> Live Channel > Language (繁體中文) 找找了 :P


2012年11月15日 星期四

[Linux] 快速架設 IMAP/IMAPs/POP3/POP3s - 使用 Dovecot @ Ubuntu 12.04

之前都寫漏漏長的 FreeBSD 架設方式,這次用 Ubuntu 12.04 架一下,果真快上許多(以下設定應該沒有符合 Ubuntu /etc/* 的規範 XD)。


$ sudo apt-get install dovecot-imapd dovecot-pop3d
$ sudo vim /etc/dovecot/dovecot.conf
protocols = pop3 pop3s imap imaps
mail_location = mbox:~/mail:INBOX=/var/mail/%u
$ sudo /etc/init.d/dovecot restart 


 可以用 telnet 和 openssl 測試自家機器:


測試 POP3:


$ telnet localhost 110   (或 openssl s_client -connect localhost:995)
...
+OK Dovecot ready
user username 
+OK
pass password
+OK Logged in.
list
+OK 1 messages:
1  ###
.
quit
+OK Loggin out. 


測試 IMAP:


$ telnet localhost 143 (或 openssl s_client -connect localhost:993)
* OK ... Dovecot ready.
- login username password
- OK .... Logged in
- select INBOX
...
* OK
* 1 EXISTS
...
- OK ... Select completed.
- logout
* BYE Logging out
- OK Logout completed. 


此外,有可能一開始剛裝完後,使用上述指令測試時出現錯誤訊息,這樣的現象是因為使用的帳號尚未有信件進來,以致於 /var/mail/username 並未建立,故只需先寄信給 username 後,系統就會幫你建立對應的 mail service 資料,如此就可以測試了。