2013年10月4日 星期五

2012年10月20日 星期六

Apple Push Notification Services (APNS)

Apple Push Notification Services Tutorial: Part 1/2
Apple Push Notification Services Tutorial: Part 2/2

 1.產生Certificate Signing Request (CSR)
Keychain Access -> Certificate Assistant-> Request a Certificate from a Certificate Authority….
儲存成 pushtest.certSigningRequest

左下方 Keys -> 選擇最下方pushtest的private key按滑鼠右鍵 -> Export "pushtest"...
儲存成pushtestkey.p12

2.建立App ID 以及 SSL certificate
Bundle Identifier 必須與 Xcode 一致
上傳 pushtest.certSigningRequest 產生 aps_development.cer 以及 aps_production.cer

3.產生 pem 檔
到目前為止你應該有以下檔案,並把它們放在 Documents/pushtest 底下
pushtest.certSigningRequest
pushtestkey.p12
aps_development.cer
aps_production.cer
開啟 Terminal 切換到 Documents/pushtest 底下

openssl x509 -in aps_development.cer -inform der     -out pushtestcert.pem

openssl pkcs12 -nocerts -out pushtestkey.pem -in pushtestkey.p12

cat pushtestcert.pem pushtestkey.pem > ck.pem

telnet gateway.sandbox.push.apple.com 2195

openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert pushtestcert.pem -key pushtestkey.pem

4.建立 Provisioning Profile
選擇 push test 的 App ID
下載 pushtest_development.mobileprovision 並匯入 Xcode



Cocos2d 以及 Cocos2d-x 模版安裝

因為步驟差不多所以寫在一起 請自行分辨

先去官方網站下載解壓縮
Cocos2d
Cocos2d-x

裡面有個 install-templates.sh 或是 install-templates-xcode.sh
用簡介取得他的目錄位置,之後要用終端機打指令執行它

安裝前建議先關閉Xcode,然後去應用程式打開終端機
打上 "cd 你剛複製的目錄位置"
再打上 "./install-templates.sh -f" 或是 "sudo ./install-templates-xcode.sh"
安裝完成後再打開Xcode開新專案看看左邊有沒有新增類別

2012年4月19日 星期四

根據內容多寡,調整cell高度

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}


cell.textLabel.text=[[theArray objectAtIndex:indexPath.row] objectForKey:@"description"];
cell.textLabel.lineBreakMode=UILineBreakModeTailTruncation; //若內容超出cell可容納範圍,最後出現"..."
cell.textLabel.numberOfLines=30; //單一cell出現的行數,0為無限

return cell;
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
NSString *text = [[theArray objectAtIndex:indexPath.row] objectForKey:@"description"];

//開始去計算全部內容,以字體大小14、lineBreakMode:UILineBreakModeTailTruncation狀態下,會得到多少的範圍寬高度
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:14.0] constrainedToSize:CGSizeMake(240.0, 480.0) lineBreakMode:UILineBreakModeTailTruncation];
//CGSizeMake(240.0, 480.0) 設定單一cell最大的寬高度,若得到的size超過這個範圍,則只會以這個為基準;

return MAX(size.height + 10, 40.0f); //單一cell高度最小會為40

}



UIViewContentModeScaleAspectFill後將多餘區域切除

UIImage *image = [UIImage imageNamed:@"image.jpg"];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 180, 300, 150)];
imageView.image = image;
imageView.contentMode = UIViewContentModeScaleAspectFill;
[self.view addSubview:imageView];


若該imgae的高度大於150
雖然使用了UIViewContentModeScaleAspectFill
仍會顯示完整的圖片
若要只限定出現150高度範圍內的圖片
需多加一段語法即可實現
imageView.clipsToBounds = YES;

若是使用xib將Mode設為Scale To Fill時
請勾選Clip Subviews即可有相同效果


轉載整理自:難纏的兔子王 - UIViewContentModeScaleAspectFill的陷阱


2012年4月9日 星期一

plist讀取

- (void)viewDidLoad

{

[superviewDidLoad];

NSString *path = [[NSBundlemainBundle] pathForResource:@"locations"ofType:@"plist"]; //plist檔案名稱、附檔名

NSData *plistData = [NSData dataWithContentsOfFile:path];

NSString *error; NSPropertyListFormat format;

NSArray *allspots = [NSPropertyListSerializationpropertyListFromData:plistData

mutabilityOption:kCFPropertyListMutableContainersAndLeaves

format:&format

errorDescription:&error];

NSString *documentsPath = [[allspots objectAtIndex:0] objectForKey:@"stitle"]; //先取第一個item, 在找key名稱為"stitle"

NSLog(@"Get: %@", documentsPath); //秀出該筆item的stitle的值

}




[轉載] NSString 常用轉換&格式化

關於 NSString 的二三事
http://furnacedigital..com/2011/04/nsstring.html