-----------------------------------------------------------------
一些 iPhone ObjC 的語法
因為用 C 用習慣了, 所以很需要 "formatter"
-----------------------------------------------------------------
[NSString stringWithFormat:@"%@ (%@)", [nameComponents objectAtIndex:2], [nameComponents objectAtIndex:1]];
-----------------------------------------------------------------
在 Table 裡面, 產生
+/- Item-Context >
這樣的效果的方式
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator :可以放 ">" 在 table cell 的右邊
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath : 可以放 +/- 在 table cell 的左邊
-----------------------------------------------------------------
在加入 code data 的時候, 不要勾選 copy file/folder 的選項, 會造成 link fail
-----------------------------------------------------------------
在 obj c 裡面, 有一個隱含的語法, 當我們在 class 裡面有一個 attribute, 比如說, TypeA AttrA; 用 proprety 去宣告.
同時 implement 了一個 TypeA AttrA { .... } 的函數, 則在 reference 到 AttrA 的時後, 會主動連結到這個函數.
2011年8月27日 星期六
Webdav first try
First, I have to setup a webdav server on my development mac, which just following the web guideline.
Second, I use litmus tool to test my webdav server.
Litmus is quite different. It uses "make" to run test, not compiles out a executive and runs test.
configure
make
make URL="http://my-webdav-server/my-upload-path" CREDS="admin admin" check
Second, I use litmus tool to test my webdav server.
Litmus is quite different. It uses "make" to run test, not compiles out a executive and runs test.
configure
make
make URL="http://my-webdav-server/my-upload-path" CREDS="admin admin" check
2011年8月12日 星期五
iPhone 的進入門檻(1) code sign
寫慣了Android apk, 轉來寫 iPhone APP, 第一個遇到的問題, 就是程式上傳. 在 Android 裡面, 只要 USB 插了, 就可以上傳, iPhone 需要的動作多很多.
1. 要有一個價值 $99 USD 的 development program ID. 這是最簡單了, 給了錢就有.
2. 用那個 ID 登錄上到 iOS Provisioning Portal
3. 瞭解一下 iPhone 程式上傳和模擬器的差別
a. 模擬器
a1. Build code
a2. Run APP
b. 手機
b1. Code sign
b2. Build code
b3. Upload code
b4. Run APP
最關鍵的就是 b2 : code sign
code sign 就是給 APP 加上開發簽署, 這個開發簽署又有分 developer 和 distributor, 我還沒使用過 distributor 簽署, 這邊先講一下 developer 開發簽署的過程
簽署的動作是把Apple 公司, 開發電腦, 開發 ID, 開發程式和手機綁在一起. 動作是 :
a. 安裝 Apple 開發簽章 apple worldwide developer relations certification
a1. 下載後面的 Worldwide Developer Relations 的 certification
a2. 執行該 certification, 這個動作會把 certification 安裝到鑰匙圈裡面
a3. 執行 應用程式 -> 工具程式 -> 鑰匙圈存取, 在鑰匙圈 - 登入, 類別 - 憑證 的 項目裡面, 會看到 Apple World Wide Relations Certification
b. 從電腦裡面產生 certification request, 以及其他準備工具
b1. 在 menu 裡面, 執行鑰匙圈存取 -> 憑證輔助程式 -> 從憑證授權要求憑證, 產生一個 certification request. 這邊的憑證授權(機構)其實就是之後要上傳的 Provisioning Portal
b2. 在 provisioning portal 裡面的 certification 頁面, 上傳該 certification request. 因為是唯一的, 所以換電腦的話, 這整個動作要重作.(當然, 如果使用的是團隊開發的授權, 就可以增加很多個 team member.)
b3. reload page, 直到看到 download 選項出現, 選 download, 下載憑證, 然後執行該憑證
b4. 開啓鑰匙圈工具, 看看登入 -> 憑證類別, 裡面應該要有
b41. Apple Worldwide Relations Certification
b42. 剛剛產生的憑證
b43. 這些憑證都有一個綠色的勾, 旁邊顯示:此憑證是有效的
b44. Double click 每個憑證, 在"信任"的項目裡面, 選擇系統預設
b45. 到此為止, 每個憑證都要是有效的
c. 幫自己的 iPhone/iPad/iPod 建檔
c1. 開啓 Xcode, 插入 iPhone 後, 在 menu 裡面選 Window -> Organizer
c2. 點一下 device 下的 iPhone, 右邊出現 iPhone 的一些內容, 其中有一個 Identifier : xxx
c3. 登入到 Provisioning Portal, 選擇 Add device, 把剛剛的 xxx 打進去, 然後 submit
c4. Reload Page, 應該看到自己的 iPhone 建檔了
d. 把 certification request 上傳到 Provisioning Portal, 加上簽章, 產生 certification. 這個動作把電腦和 Developer ID 綁在一起.
c1. 如果 a-c 都是正確的, 那在開啓 xcode, 插入 iPhone 後, 在 menu 裡面選 Window -> Organizer
c2. Device 下的 iPhone, 下面有一個 Provision Profiles, 執行底下的 refresh
c3. c2 會產生一個 team provisioning profile: * 的 profile
c4. 在各個開發的 APP 裡面, 確認每個 APP -> Project -> build settings -> Code Signing -> 選 iPhone Developer
c5. Clean, rebuild
1. 要有一個價值 $99 USD 的 development program ID. 這是最簡單了, 給了錢就有.
2. 用那個 ID 登錄上到 iOS Provisioning Portal
3. 瞭解一下 iPhone 程式上傳和模擬器的差別
a. 模擬器
a1. Build code
a2. Run APP
b. 手機
b1. Code sign
b2. Build code
b3. Upload code
b4. Run APP
最關鍵的就是 b2 : code sign
code sign 就是給 APP 加上開發簽署, 這個開發簽署又有分 developer 和 distributor, 我還沒使用過 distributor 簽署, 這邊先講一下 developer 開發簽署的過程
簽署的動作是把Apple 公司, 開發電腦, 開發 ID, 開發程式和手機綁在一起. 動作是 :
a. 安裝 Apple 開發簽章 apple worldwide developer relations certification
a1. 下載後面的 Worldwide Developer Relations 的 certification
a2. 執行該 certification, 這個動作會把 certification 安裝到鑰匙圈裡面
a3. 執行 應用程式 -> 工具程式 -> 鑰匙圈存取, 在鑰匙圈 - 登入, 類別 - 憑證 的 項目裡面, 會看到 Apple World Wide Relations Certification
b. 從電腦裡面產生 certification request, 以及其他準備工具
b1. 在 menu 裡面, 執行鑰匙圈存取 -> 憑證輔助程式 -> 從憑證授權要求憑證, 產生一個 certification request. 這邊的憑證授權(機構)其實就是之後要上傳的 Provisioning Portal
b2. 在 provisioning portal 裡面的 certification 頁面, 上傳該 certification request. 因為是唯一的, 所以換電腦的話, 這整個動作要重作.(當然, 如果使用的是團隊開發的授權, 就可以增加很多個 team member.)
b3. reload page, 直到看到 download 選項出現, 選 download, 下載憑證, 然後執行該憑證
b4. 開啓鑰匙圈工具, 看看登入 -> 憑證類別, 裡面應該要有
b41. Apple Worldwide Relations Certification
b42. 剛剛產生的憑證
b43. 這些憑證都有一個綠色的勾, 旁邊顯示:此憑證是有效的
b44. Double click 每個憑證, 在"信任"的項目裡面, 選擇系統預設
b45. 到此為止, 每個憑證都要是有效的
c. 幫自己的 iPhone/iPad/iPod 建檔
c1. 開啓 Xcode, 插入 iPhone 後, 在 menu 裡面選 Window -> Organizer
c2. 點一下 device 下的 iPhone, 右邊出現 iPhone 的一些內容, 其中有一個 Identifier : xxx
c3. 登入到 Provisioning Portal, 選擇 Add device, 把剛剛的 xxx 打進去, 然後 submit
c4. Reload Page, 應該看到自己的 iPhone 建檔了
d. 把 certification request 上傳到 Provisioning Portal, 加上簽章, 產生 certification. 這個動作把電腦和 Developer ID 綁在一起.
c1. 如果 a-c 都是正確的, 那在開啓 xcode, 插入 iPhone 後, 在 menu 裡面選 Window -> Organizer
c2. Device 下的 iPhone, 下面有一個 Provision Profiles, 執行底下的 refresh
c3. c2 會產生一個 team provisioning profile: * 的 profile
c4. 在各個開發的 APP 裡面, 確認每個 APP -> Project -> build settings -> Code Signing -> 選 iPhone Developer
c5. Clean, rebuild
2011年8月9日 星期二
See NIB identity
1.
When managing nib (.xib) file, we need to enable
View -> Utilities -> identity inspector
2.
Implement button event, we can
1. Layout a button on the NIB file with "Utilities -> attribute inspector"
2. On the button, hold "control" key on the keyboard and use the mouse to drag a "line" into assistant
3. It will appear a small window that helps adding an action
When managing nib (.xib) file, we need to enable
View -> Utilities -> identity inspector
2.
Implement button event, we can
1. Layout a button on the NIB file with "Utilities -> attribute inspector"
2. On the button, hold "control" key on the keyboard and use the mouse to drag a "line" into assistant
3. It will appear a small window that helps adding an action
Obj C notes
1. @interface
Used to declare a class. To declare a class MyClass inheriting MyParentClass, we can write
/* Code blocks begin */
@interface MyClass : MyParentClass {
}
+ ClassMethods:(type1)param1 :(type2)param2
- InstanceMethods:(type1)param1 :(type2)param2 SomeDescriptiveNotes:(type3)param3
// The word "SomeDescriptiveNotes" only stand for programmer read and will not influence any real behavior
/* Code blocks end */
2. @implementation : the body of a class
3. Instantiation :
1. MyClass *myCls = [[MyClass alloc] init];
2. MyClass *myCls = [[MyClass alloc] initWithSomeParameters];
3. MyClass *myCls = [MyClass new];
4. Protocol ==> C++ abstract class multiple inheritance or Java interface
5. Message forwarding
Implement a call passing behavior. When main send a message "Greeting" to ClassA, ClassA doesn't implement the message, and ClassB does, then ClassA can pass the "Greeting" message to ClassB without handling locally
6. Category
Behaving like inheritance, category adopt parent class's data, including private, and add/replace existing methods.
/* Code blocks begin */
@interface ParentClass (CategoryA) {
}
- CategoryA_method1;
- CategoryA_method2;
@end
/* Code blocks end */
The use of ParentClass with CategoryA can have CategoryA_method1 and CategoryA_method2 methods
7. Instance variable, property and synthesize
Use of property/synthesize ==> add special attribute(readonly/read-write/copy/assign/retain/atomic/nonatomic to instance variable
@interface ClassA : NSObject {
public:
int var1;
provate:
int var2;
}
@property (copy) int var1; // Declare var1 as "copy" attribute
@property (readonly) int var2; // Declare var2 as "readonly" attribute
/*** Note ***/
/* Copy, retain are reference to mutable subclass ? */
/* Copy : int x = 5; myClass.var1 = x; x = 10; var1 will be 5 */
/* Retain : int x = 5; myClass.var1 = x; x = 10; var1 will be 10 */
When synthesize a variable, it will generate "setter" and "getter" automatically
@synthesize var1;
/* Generate : void setVar1:(int)v1
int getVar1
*/
Used to declare a class. To declare a class MyClass inheriting MyParentClass, we can write
/* Code blocks begin */
@interface MyClass : MyParentClass {
}
+ ClassMethods:(type1)param1 :(type2)param2
- InstanceMethods:(type1)param1 :(type2)param2 SomeDescriptiveNotes:(type3)param3
// The word "SomeDescriptiveNotes" only stand for programmer read and will not influence any real behavior
/* Code blocks end */
2. @implementation : the body of a class
3. Instantiation :
1. MyClass *myCls = [[MyClass alloc] init];
2. MyClass *myCls = [[MyClass alloc] initWithSomeParameters];
3. MyClass *myCls = [MyClass new];
4. Protocol ==> C++ abstract class multiple inheritance or Java interface
5. Message forwarding
Implement a call passing behavior. When main send a message "Greeting" to ClassA, ClassA doesn't implement the message, and ClassB does, then ClassA can pass the "Greeting" message to ClassB without handling locally
6. Category
Behaving like inheritance, category adopt parent class's data, including private, and add/replace existing methods.
/* Code blocks begin */
@interface ParentClass (CategoryA) {
}
- CategoryA_method1;
- CategoryA_method2;
@end
/* Code blocks end */
The use of ParentClass with CategoryA can have CategoryA_method1 and CategoryA_method2 methods
7. Instance variable, property and synthesize
Use of property/synthesize ==> add special attribute(readonly/read-write/copy/assign/retain/atomic/nonatomic to instance variable
@interface ClassA : NSObject {
public:
int var1;
provate:
int var2;
}
@property (copy) int var1; // Declare var1 as "copy" attribute
@property (readonly) int var2; // Declare var2 as "readonly" attribute
/*** Note ***/
/* Copy, retain are reference to mutable subclass ? */
/* Copy : int x = 5; myClass.var1 = x; x = 10; var1 will be 5 */
/* Retain : int x = 5; myClass.var1 = x; x = 10; var1 will be 10 */
When synthesize a variable, it will generate "setter" and "getter" automatically
@synthesize var1;
/* Generate : void setVar1:(int)v1
int getVar1
*/
2011年8月8日 星期一
Android NDK 寫法和注意事項
1. 如果沒有做自定的 JNI export table, 預設的 export table 和 package name 以及 activity name 息息相關
package name : com.android.animal
activity name : DogActivity
native functions :
void funcA(void);
int funcB(int bin);
int[] funcC(int[] cin);
JNI export functions:
JNIEXPORT void JNICALL
Java_com_android_animal_DogActivity_funcA
(JNIEnv * env, jobject obj);
JNIEXPORT jint JNICALL
Java_com_android_animal_DogActivity_funcB
(JNIEnv * env, jobject obj, jint bin);
JNIEXPORT jintArray JNICALL
Java_com_android_animal_DogActivity_funcA
(JNIEnv * env, jobject obj, jintArray jarra);
2. array 可以轉換成 C pointer, 同時提供 array size
int *arra_ptr = (*env)->GetIntArrayElements(env, jarra, 0);
jsize sz = (*env)->GetArrayLength(env, jarra);
3. 重 build jni 之後, 必須要把 Android project clean & rebuild
package name : com.android.animal
activity name : DogActivity
native functions :
void funcA(void);
int funcB(int bin);
int[] funcC(int[] cin);
JNI export functions:
JNIEXPORT void JNICALL
Java_com_android_animal_DogActivity_funcA
(JNIEnv * env, jobject obj);
JNIEXPORT jint JNICALL
Java_com_android_animal_DogActivity_funcB
(JNIEnv * env, jobject obj, jint bin);
JNIEXPORT jintArray JNICALL
Java_com_android_animal_DogActivity_funcA
(JNIEnv * env, jobject obj, jintArray jarra);
2. array 可以轉換成 C pointer, 同時提供 array size
int *arra_ptr = (*env)->GetIntArrayElements(env, jarra, 0);
jsize sz = (*env)->GetArrayLength(env, jarra);
3. 重 build jni 之後, 必須要把 Android project clean & rebuild
Android Sensor
Android 手機上最特殊的, 就是無所不在的 sensors,透過這些 sensor, 我們可以創造和電腦不一樣的控制方式
Sensor基本的程式寫法
1. 支援 SensorEventListener
public class SensorTestActivity extends Activity implements SensorEventListener
2. 取得 sensor 的服務
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
這個服務, 會在 sensor 有資料的時候, 把資料傳給註冊的程式
**注意**
有些 sensor 會一直傳資料出來, 像是accelerator, magnetic, gyroscope
有些 sensor 會在有資料的時候才送, 像是 NFC
**不必再注意**
3. 註冊希望接受的 sensor event
mSensorManager.registerListener(this,
mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_NORMAL);
4. 接收sensor event
public void onSensorChanged(SensorEvent event) {
if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
//Do what you need to do
}
}
Sensor基本的程式寫法
1. 支援 SensorEventListener
public class SensorTestActivity extends Activity implements SensorEventListener
2. 取得 sensor 的服務
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
這個服務, 會在 sensor 有資料的時候, 把資料傳給註冊的程式
**注意**
有些 sensor 會一直傳資料出來, 像是accelerator, magnetic, gyroscope
有些 sensor 會在有資料的時候才送, 像是 NFC
**不必再注意**
3. 註冊希望接受的 sensor event
mSensorManager.registerListener(this,
mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_NORMAL);
4. 接收sensor event
public void onSensorChanged(SensorEvent event) {
if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
//Do what you need to do
}
}
2011年8月3日 星期三
Linux and tty terminal
Ubuntu 要怎樣跟 uart/com port 連呢
1. 用 moserial ---- under studying
2. 用 screen
screen /dev/ttyS0 115200,cs8,-ixon,-ixon,istrip
.screenrc
# kill startup message
startup_message off
# define a bigger scrollback, default is 100 lines
defscrollback 1024
# remap CTRL-A to CTRL-]
escape ^]]
# status bar
hardstatus on
hardstatus alwayslastline "%{rk}%H %{gk}%c %{yk}%M%d %{wk}%?%-Lw%?%{bw}%n*%f %t%?(%u)%?%{wk}%?%+Lw%?"
1. 用 moserial ---- under studying
2. 用 screen
screen /dev/ttyS0 115200,cs8,-ixon,-ixon,istrip
.screenrc
# kill startup message
startup_message off
# define a bigger scrollback, default is 100 lines
defscrollback 1024
# remap CTRL-A to CTRL-]
escape ^]]
# status bar
hardstatus on
hardstatus alwayslastline "%{rk}%H %{gk}%c %{yk}%M%d %{wk}%?%-Lw%?%{bw}%n*%f %t%?(%u)%?%{wk}%?%+Lw%?"
2011年8月2日 星期二
Handling multiple lines in shell script
Shell script is good to work with ASCII line contents. When considering multiple lines, it needs some techniques.
1. Use pipe and read
cat A_File_With_Lines.txt | {
while :; do
read line
work_with line
if [ line_condition_end ]; then
break
fi
done
}
** NITES **
Two issues :
a. line_condition_end is very very very important because the "EOF" read will cause the shell to exit running.
b. The variables inside the | { } scope can't be used outside the braces
2. Use for loop
for line_in_file in $(cat A_File_With_Lines.txt); do
work_with line
done
** NITES **
a. This method requires the "lines in the file" do not contain any white space, tab, and other special words which can't be directly processed in script.
b. Because of a, this method is specially good for handling "files list which generated by ls or find"
1. Use pipe and read
cat A_File_With_Lines.txt | {
while :; do
read line
work_with line
if [ line_condition_end ]; then
break
fi
done
}
** NITES **
Two issues :
a. line_condition_end is very very very important because the "EOF" read will cause the shell to exit running.
b. The variables inside the | { } scope can't be used outside the braces
2. Use for loop
for line_in_file in $(cat A_File_With_Lines.txt); do
work_with line
done
** NITES **
a. This method requires the "lines in the file" do not contain any white space, tab, and other special words which can't be directly processed in script.
b. Because of a, this method is specially good for handling "files list which generated by ls or find"
Notes to generate and apply patch files in Linux world
There are several types of generate/apply patches in linux world
1. basic diff/patch
generate : diff -Nur file1 file2 > file1_file2.patch
apply : under file1's folder, patch -p 0 < file1_file2.patch
************ NOTES ***********
a. patch -p n means ignore first n directory levels in file1_file2.patch file part.
b. patch can apply to svn/git patches
2. SVN diff/patch
generate : svn diff file1 > ~/file1_fixes.patch
apply : use 1(diff/patch) to apply patch
3. GIT diff/patch
generate : git diff file1
apply : git apply file1.patch
************ NOTES ***********
a. always do --stat and --check before applying a patch through git
git apply --stat file1.patch
git apply --check file1.patch
b. git am can use to replace git apply, with git am can give signoff option
git am --signoff < fix_empty_poster.patch
1. basic diff/patch
generate : diff -Nur file1 file2 > file1_file2.patch
apply : under file1's folder, patch -p 0 < file1_file2.patch
************ NOTES ***********
a. patch -p n means ignore first n directory levels in file1_file2.patch file part.
b. patch can apply to svn/git patches
2. SVN diff/patch
generate : svn diff file1 > ~/file1_fixes.patch
apply : use 1(diff/patch) to apply patch
3. GIT diff/patch
generate : git diff file1
apply : git apply file1.patch
************ NOTES ***********
a. always do --stat and --check before applying a patch through git
git apply --stat file1.patch
git apply --check file1.patch
b. git am can use to replace git apply, with git am can give signoff option
git am --signoff < fix_empty_poster.patch
訂閱:
意見 (Atom)