2011年3月30日 星期三

sharemgr remove share problem

when an asterisk (*) preceding the share. it is a temporary share


We can not delete it


user can access temporary share


It will disappear after reboot 


how to create temporary share:
ex:

sharemgr add-share -t -r peter -s /Test/imac/peter smb_group










share problem:
auto create nfs share because /lib/svc/method/nfs-server call "sharemgr start -P nfs -a" to enable nfs on all group

solution:
not use -a, use specific nfs group name
ex:
sharemgr start -P nfs nfs_group








判斷file是否存在 on iOS

if([[NSFileManager defaultManager] fileExistsAtPath:path])
{

}

macToday magazine的iPad版推出了

macToday magazine的iPad版推出了,做得還不錯。
http://itunes.apple.com/tw/app/id420948459?mt=8

install gcc on solaris

pkg install gcc-dev
or
pkg install SUNWgcc

2011年3月29日 星期二

save data using plist

只有以下類別的物件可以利用writeToFile:atomically:存入plist

NSArray
NSMutableArray
NSDictionary
NSMutableDictionary
NSData
NSMutableData
NSString
NSMutableString
NSNumber
NSDate

UITextField: 按下鍵盤上的return後,讓鍵盤消失

關鍵:  UIControlEventEditingDidEndOnExit和resignFirstResponder


ex:
          Enter鍵按下時觸發的method

    -(void)textFieldDone:(UITextField*)textField
    {
         [textField resignFirstResponder];
    }


          建立TextField

    textField = [[UITextField alloc] initWithFrame:
                              CGRectMake(5, 5,  
                                         image.size.width,
                                         image.size.height)];
    [imageView addSubview:textField];
    [textField addTarget:self  
          action:@selector(textFieldDone:)  
         forControlEvents:UIControlEventEditingDidEndOnExit];
    [textField release];

2011年3月28日 星期一

zfs

import another pool
zpool import Test

show pools
zpool list

App's folder structure on iOS

每個App皆有專屬自己access的directory
主要有以下三種directory:

1.   Documents

2.   Library
      NSUserDefaults-based preference存在Library/Preferences folder

3.  tmp
     存在tmp下的file,不會和iTunes同步。但我們要自己將tmp下的檔案殺掉,
     它們不會因為reboot而消失。

get time string from NSDate

+(NSString*)getTimeStrFromDate:(NSDate*)date
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *timeStr = [dateFormatter stringFromDate:date];
    [dateFormatter release];
    return timeStr;
}

天梯

"天梯"的愛情故事。六歲的時候他認識了比他大十歲的她。縱使受盡白眼和閒言閒語,在十六歲那一年他跟她說:「讓我照顧你一生一世好嗎?」為了避開俗世,他們遠離塵世到深山定居,過著艱苦但快樂的生活。上山下山步步艱難,為了怕妻子受傷,他決定用雙手開墾石級。結果用了五十多年的時間,鑿了一條六千多級的石梯。終於在 02 年一隊登山隊發現了這條偉大的天梯和這個驚世的愛情故事。故事主人翁劉國江先生在 07 年與世長辭,她的妻子決定留在沒山,終生與天梯廝守。 











2011年3月27日 星期日

Time Machine

use solaris as time machine disk

1. enable AFP and share dir

2. enable bonjour
   (option, this will make share automatically  show on the finder)

3. edit AppleVolumes.default
   add tm option for share
   ex:
   "/Pool-1/testTime2" "testTime2" cnidscheme:dbd options:acls,upriv,nostat,tm

4. enable acl full permission for everyone for share folder
   ( this step is for netatalk version < 2.2)


.sparsebundle dir:
time machine will create a .sparsebundle dir
this dir contains backup data

use time machine on mac:

  1.  setting  -> time machine

2. Select Disk for backup
 

3. select disk ( ex: NAS volume)
 

4.  Back up Now ( start backup)
 

5. Enter Time Machine
    Watch & restore content in different time


時區處理 on iOS

取得device上GMT的offset
NSTimeZone *currentTimeZone = [NSTimeZone localTimeZone];
NSInteger offset = [currentTimeZone secondsFromGMT];
以台灣為例,
offset為28800 ( + 8 hour)

距離1970的秒數:
每台電腦取得的值是一樣的
不管在美國或台灣,
所取得的值皆對應GMT + 0的時間。
假設從美國的server取得秒數為1301322715,
在台灣的iOS device上,
利用    
[NSDate dateWithTimeIntervalSince1970:1301322715]
取得的時間,
即可轉成台灣當地的時間。








sandbox & production environment for iOS push

sandbox environment:
1. provisioning profile
    development provisioning profile
    provisioning profile以iPhone Developer開頭
2. Apple server:
    gateway.push.apple.com
3. certificate
    Development Push SSL Certificate


production environment
1. provisioning profile
    distribution provision profile (ad-hoc or App store)
    provisioning profile以iPhone Distribution開頭
2. Apple server:
   gateway.sandbox.push.apple.com
3. certificate
   Production Push SSL Certificate

provisioning profile for push notification

can not use wildcard App ID
( However, in app purchase's provisioning profile can use wildcard App ID)

當provisioning profile對到的App ID有enable push時,
provisioning profile裡將包含aps-environment這組key。
(使用text editor打開provisioning profile即可檢查。)

install App problem on iOS device

problem: The executable was signed with invalid entitlements
device ID沒有加到provisioning profile裡

2011年3月26日 星期六

custom delegate

兩個物件之間通訊的方式有很多,
透過自行訂義的@protocol是其中一種。
而我們往往將protocol名字取名為某種delegate。

將NSString變為合法的URL

使用

- (NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)enc

ex:
url = [url   
      stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];



Download File Asynchronously

利用NSURLConnection的initWithRequest:delegate:startImmediately: method建立connection,
於startImmediately傳入yes表示馬上開始download
NSURL *url = [NSURL URLWithString:urlStr];
self.downloadData = [[NSMutableData alloc] init];
[self.downloadData release];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
self.downloadConnection = [[NSURLConnection alloc
                                   initWithRequest:req  
                                   delegate:self
                                   startImmediately:YES];
[self.downloadConnection release];


常用的NSURLConnectionDelegate method


開始download後,首先被呼叫的method
由於一個request可能收到多個response,
所以將data的長度設為0,
清除之前收到的data


- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    NSLog(@"didReceiveResponse");
    [self.downloadData setLength:0];
}

將收到的data累加進downloadData
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    NSLog(@"data %d", [data length]);
    [self.downloadData appendData:data];

}

成功完成下載時被呼叫
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    NSLog(@"Successfully connectionDidFinishLoading");

}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    NSLog(@"error %@", error);
}


測試輸出:

2011-03-26 17:50:00.690 DownloadAsync[13125:207] didReceiveResponse
2011-03-26 17:50:00.692 DownloadAsync[13125:207] data 3310
2011-03-26 17:50:00.693 DownloadAsync[13125:207] data 13258
2011-03-26 17:50:00.694 DownloadAsync[13125:207] Successfully connectionDidFinishLoading



Open Quickly - 從Xcode快速找到相關資訊

cmd + shift + o

Download File Synchronously

利用NSURLConnection的sendSynchronousRequest:returningResponse:error: method

NSString *urlStr = @"http://deeploveapple.blogspot.com/";
NSURL *url = [NSURL URLWithString:urlStr];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:req   
   returningResponse:nil error:&error];
if(data)
{
   NSString *str = [[NSString alloc] initWithData:data                                           
      encoding:NSUTF8StringEncoding];
   NSLog(@"str %@", str);
   [str release];
}
else
{
   NSLog(@"error %@", error);
}

利用curl傳送post by PHP

<?php
define("SERVER_URL", "https://go.urbanairship.com");
define("PUSH", "/api/push/");
define("BROADCAST", "/api/push/broadcast/");
define("APP_KEY", "8Du08OUPTeecwya111");
define("APP_MASTER_SECRET", "EBZ5mQLQR333");

function send($post_data, $url)
{
$post_data = json_encode($post_data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, APP_KEY.":".APP_MASTER_SECRET);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch,CURLOPT_HTTPHEADER,array (
        "Content-type: application/json"
));
$output = curl_exec($ch);
echo $output;
curl_close($ch);
}

function sendBroadcast($msg, $badge)
{
$url = SERVER_URL.BROADCAST;
$post_data = array (
        "aps" => array( "alert" => $msg,
"badge" => $badge,
"sound" => "frog.caf")
);
send($post_data, $url);
}

function sendPush($msg, $tokens)
{
$url = SERVER_URL.PUSH;
print_r( $tokens);
$post_data = array (
        "aps" => array( "alert" => $msg ),
"device_tokens" => $tokens
);
send($post_data, $url);
}

sendBroadcast("hi", 3);
sendPush("hi", array("BDD076692A89126ED3C5EA057F7C2535312"));

?>

利用NSXMLParser parse梁朝偉和劉德華

xml檔範例:



<?xml version="1.0" encoding="UTF-8"?>
    <永遠的偶像>
        <名字 name="梁朝偉">
            <音樂>為情所困</音樂>
            <movie>俠骨仁心</movie>
        </名字>
        <名字 name="劉德華">
            <音樂>來生緣</音樂>
            <movie>孤男寡女</movie>
        </名字>
    </永遠的偶像>
</xml>




利用xml檔案初始NSXMLParser物件
NSData *data = [NSData dataWithContentsOfFile:path];
xmlParser = [[NSXMLParser alloc] initWithData:data];


設定delegate,如此才能於NSXMLParserDelegate的method被呼叫時做處理
[xmlParser setDelegate:self];


 呼叫NSXMLParser物件的parse method開始進行parse
 parse method is a block call,做完才return
[xmlParser parse];
[xmlParser release];


以下三個method為我們最常使用的NSXMLParserDelegate method


1. 於遇到XML tag開頭時被呼叫,可取得tag的名稱以及tag裡的attribute



-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    NSLog(@"didStartElement");
    NSLog(@"elementName %@", elementName);
    for(id key in attributeDict)
    {
        NSLog(@"attribute %@", [attributeDict objectForKey:key]);
    }
}



2. 找到XML tag所包含的內容
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    NSLog(@"foundCharacters %@", string);
}



3. 於遇到XML tag結尾時被呼叫


- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
    NSLog(@"didEndElement");
    NSLog(@"elementName %@", elementName);    
}

測試輸出:
2011-03-26 16:04:46.172 XmlParse[12296:207] didStartElement
2011-03-26 16:04:46.175 XmlParse[12296:207] elementName 永遠的偶像
2011-03-26 16:04:46.177 XmlParse[12296:207] foundCharacters 
        
2011-03-26 16:04:46.178 XmlParse[12296:207] didStartElement
2011-03-26 16:04:46.179 XmlParse[12296:207] elementName 名字
2011-03-26 16:04:46.179 XmlParse[12296:207] attribute 梁朝偉
2011-03-26 16:04:46.180 XmlParse[12296:207] foundCharacters 
            
2011-03-26 16:04:46.181 XmlParse[12296:207] didStartElement
2011-03-26 16:04:46.181 XmlParse[12296:207] elementName 音樂
2011-03-26 16:04:46.182 XmlParse[12296:207] foundCharacters 為情所困
2011-03-26 16:04:46.183 XmlParse[12296:207] didEndElement
2011-03-26 16:04:46.184 XmlParse[12296:207] elementName 音樂
2011-03-26 16:04:46.185 XmlParse[12296:207] foundCharacters 
            
2011-03-26 16:04:46.185 XmlParse[12296:207] didStartElement
2011-03-26 16:04:46.186 XmlParse[12296:207] elementName movie
2011-03-26 16:04:46.187 XmlParse[12296:207] foundCharacters 俠骨仁心
2011-03-26 16:04:46.188 XmlParse[12296:207] didEndElement
2011-03-26 16:04:46.189 XmlParse[12296:207] elementName movie
2011-03-26 16:04:46.190 XmlParse[12296:207] foundCharacters 
        
2011-03-26 16:04:46.191 XmlParse[12296:207] didEndElement
2011-03-26 16:04:46.192 XmlParse[12296:207] elementName 名字
2011-03-26 16:04:46.193 XmlParse[12296:207] foundCharacters 
        
2011-03-26 16:04:46.194 XmlParse[12296:207] didStartElement
2011-03-26 16:04:46.195 XmlParse[12296:207] elementName 名字
2011-03-26 16:04:46.196 XmlParse[12296:207] attribute 劉德華
2011-03-26 16:04:46.196 XmlParse[12296:207] foundCharacters 
            
2011-03-26 16:04:46.197 XmlParse[12296:207] didStartElement
2011-03-26 16:04:46.198 XmlParse[12296:207] elementName 音樂
2011-03-26 16:04:46.198 XmlParse[12296:207] foundCharacters 來生緣
2011-03-26 16:04:46.199 XmlParse[12296:207] didEndElement
2011-03-26 16:04:46.200 XmlParse[12296:207] elementName 音樂
2011-03-26 16:04:46.201 XmlParse[12296:207] foundCharacters 
            
2011-03-26 16:04:46.202 XmlParse[12296:207] didStartElement
2011-03-26 16:04:46.202 XmlParse[12296:207] elementName movie
2011-03-26 16:04:46.203 XmlParse[12296:207] foundCharacters 孤男寡女
2011-03-26 16:04:46.204 XmlParse[12296:207] didEndElement
2011-03-26 16:04:46.204 XmlParse[12296:207] elementName movie
2011-03-26 16:04:46.206 XmlParse[12296:207] foundCharacters 
        
2011-03-26 16:04:46.206 XmlParse[12296:207] didEndElement
2011-03-26 16:04:46.207 XmlParse[12296:207] elementName 名字
2011-03-26 16:04:46.208 XmlParse[12296:207] foundCharacters 
    
2011-03-26 16:04:46.210 XmlParse[12296:207] didEndElement
2011-03-26 16:04:46.212 XmlParse[12296:207] elementName 永遠的偶像






pragma mark

利用 #pragma mark - 分類物件的資訊清單,不同資訊間以線條區隔
ex:

#pragma mark - NSXMLParserDelegate


NSData

+(id)dataWithContentsOfFile:(NSString *)path;
從檔案產生NSData物件

2011年3月25日 星期五

NSString & NSMutableString

-(NSString *)stringByAppendingString:(NSString *)aString;
將aString加到原來字串的結尾

NSDictionary & NSMutableDictionary

-(void)addEntriesFromDictionary:(NSDictionary *)otherDictionary;
otherDictionary裡的elements加入dic裡

memory management in Objective-C

@property裡的設定:
     設成@property(copy)
     轉化為setter:
     ex:


  -(void)setName:(NSString*)newName
  {
     NSString *temp = name;
     name = [newName copyWithZone:nil];
     [temp release];
  }

     設成@property(retain)

     轉化為setter:
     ex:
     -(void)setName:(NSString*)newName
  {
    [newName retain];
    [name release];
    name = newName;
  }



garbage collection:
當有garbage collection,在@property裡設定retain其實和assign是一樣的。

screenshot on mac


Command-Shift-4:
set file format: defaults write com.apple.screencapture type tiff

博客來銷售top 5

pc home銷售排行

天瓏暢銷排行

multitasking on iOS

判斷是否support多工

UIDevice *device = [UIDevice currentDevice];
if([device isMultitaskingSupported])
{
        
}

notification on iOS and Cocoa

注冊接收notification
ex:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(test:) name:@"TEST_NOTIFICATION" object:nil];
addObserver: 接收notification的物件
object: 有興趣的對象,也就是發出notification的對象。nil表示不限對象。


How Mac OS X Came To Be

http://www.cultofmac.com/how-mac-os-x-came-to-be-exclusive-10th-anniversary-story/87889

jsp tag

Scriptlet tag 
execute a java source code
ex:
<% out.println("Hello World"); %>


Expression tag 

enclosed between <%= and %>
is short for out.println()
ex:
<%= new java.util.Date() %>
--> Tue Jul 27 11:42:40 CST 2010

2011年3月24日 星期四

install package on solaris

install:
pkg install gcc-dev


install & show detail info:


pkg install -v gcc-dev

array

ArrayList:
get size:
ex:
myList.size();

得到iOS device資訊 (get iOS device info)

1. 得到 device ID

UIDevice *device = [UIDevice currentDevice];
NSString *uniqueIdentifier = [device uniqueIdentifier];
    

git

1. 將local端的資料上傳到server端的某個branch
ex:
git push origin testBranch
testBranch是branch的名稱

2. add local project to remote server
ex:
git remote add origin git@github.com:deeplovepan/DeeploveProgram.git


git push -u origin master

3. 比較不同的branch
git diff --name-status branch1 branch2

4. 比較不同branch的某個檔案
git difftool branch1:config/test.m branch2:config/test.m

2011年3月21日 星期一

php語法

php file以 <?php 開頭,
以  ?> 結尾

php command

run php script
ex:
php test.php

push by Urban Airship

API reference:
http://urbanairship.com/docs/push.html

利用curl發送broadcast
curl -X POST -u "abcd:defg" -H "Content-Type: application/json" --data '{"aps":{"alert":"hello"}}' https://go.urbanairship.com/api/push/broadcast/
說明:
abcd是app key, defg是app master secret

利用curl發送push:
curl -X POST -u "abcd:defg" -H "Content-Type: application/json" --data '{"device_tokens":["BDD076692A89126ED3C5EA057F7C253534807D6F30C04FB67F01FCDD5BDDCB7B"] , "aps":{"alert":"hello"}}' https://go.urbanairship.com/api/push/
說明:
BDD076692A89126ED3C5EA057F7C253534807D6F30C04FB67F01FCDD5BDDCB7B is device token

在iOS device上使用urban airship提供的library
reference:
http://urbanairship.com/docs/apns_test_client.html

awesome note

iOS上評價極高的to do App

http://bridworks.com/anote/en/main/index.php

core data model的讀寫

1. 新增一行資料至table
ex:
假設model的類別為Person

Person *person = [NSEntityDescription    
   insertNewObjectForEntityForName:@"Person" 
   inManagedObjectContext:self.managedObjectContext];
if(person != nil)
{
        person.age = [NSNumber numberWithInt:1];
        person.name = @"peter";
        
        NSError *saveError = nil;
        if([self.managedObjectContext save:&saveError] == YES)
        {
            NSLog(@"save new rocord successfully");
        }
}
說明:
利用insertNewObjectForEntityForName:inManagedObjectContext: method新增資料。不過這只是暫時的,若要真的將資料存入database,需呼叫NSManagedObjectContext物件的save: method


2. 從table讀取資料
ex:
假設model的類別為Person
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc
    init];

NSEntityDescription *entity = [NSEntityDescription  
    entityForName:@"Person" 
    inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];

NSError *error = nil;
NSArray *personArray = [self.managedObjectContext 
    executeFetchRequest:fetchRequest error:&error];
for(Person *person in personArray)
{
   NSLog(@"name %@", person.name);
}
說明:
(1)利用NSFetchRequest物件設定尋找的條件
(2)運用NSManagedObjectContext物件的executeFetchRequest:error: 
   method尋找符合條件的資料。