由於租用了VPS也買了網域,請至以下網址觀看新的部落格吧。
http://blog.dreambreakerx.com/
歡迎訂閱 XD
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
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 模版安裝
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的值
}
[轉載] Objective C 字串連接 & 型別轉換
/*字串連接*/
在java裡面我們常常用到"+"來連接兩個字串 但在objective c似乎不是這樣用
以下用一個例子解釋
float weight=benefit2/7700;
//將float轉成string
NSString* Text = [[NSString alloc] initWithFormat:@"%f", weight];
NSString* Text1=@"你會瘦";
NSString* Text2=@"kg";
//將三個字串連結在一起
NSString *ConText = [NSString stringWithFormat:@"%@%@%@", Text1,Text, Text2];
/*型別轉換*/
// 將字串轉換成int
NSString *intString = @"1";
int value = [intString intValue];
// 將字串轉換成float
NSString *floatString = @"10.00";
float value = [floatString floatValue];
// 將字串轉換成double
NSString *doubleString = @"10.000000";
double value = [doubleString doubleValue];
//將float轉換成字串float weight=benefit2/7700;
NSString* Text = [[NSString alloc] initWithFormat:@"%f", weight];
//釋放記憶體[Text release];
//將int轉換成字串
int weight=5;
NSString* Text = [[NSString alloc] initWithFormat:@"%d", weight];
//釋放記憶體
[Text release];
/*綜合範例*/
在java裡面我們常常用到"+"來連接兩個字串 但在objective c似乎不是這樣用
以下用一個例子解釋
float weight=benefit2/7700;
//將float轉成string
NSString* Text = [[NSString alloc] initWithFormat:@"%f", weight];
NSString* Text1=@"你會瘦";
NSString* Text2=@"kg";
//將三個字串連結在一起
NSString *ConText = [NSString stringWithFormat:@"%@%@%@", Text1,Text, Text2];
/*型別轉換*/
// 將字串轉換成int
NSString *intString = @"1";
int value = [intString intValue];
// 將字串轉換成float
NSString *floatString = @"10.00";
float value = [floatString floatValue];
// 將字串轉換成double
NSString *doubleString = @"10.000000";
double value = [doubleString doubleValue];
//將float轉換成字串float weight=benefit2/7700;
NSString* Text = [[NSString alloc] initWithFormat:@"%f", weight];
//釋放記憶體[Text release];
//將int轉換成字串
int weight=5;
NSString* Text = [[NSString alloc] initWithFormat:@"%d", weight];
//釋放記憶體
[Text release];
/*綜合範例*/
-(IBAction)buttonA:(UIButton *)text;{
NSString *bb = @"You Pressed ";
aa = @"You Pressed ";
switch (text.tag) {
case 1:
//alert: You Pressed News Feed
aa = [NSString stringWithFormat:@"%@News Feed",bb];
break;
case 2:
//較有效率 alert: You Pressed Profile
aa = [aastringByAppendingString:@"Profile"];
break;
case 3:
//alert: You Pressed You Pressed Friends
aa = [aa stringByAppendingFormat:@"%@Friends",bb];
break;
default:
//int轉字串
aa = [@"not yet"stringByAppendingString:[[NSStringalloc] initWithFormat:@"(%d)", text.tag]];
break;
}
NSLog(@"你按了:%d - %@", text.tag, aa);
//AlertView 提示功能
UIAlertView * alertA = [[UIAlertViewalloc]initWithTitle:@"News Feed"message:aa
delegate:self cancelButtonTitle:@"OK"
otherButtonTitles: nil];
//多加一個按鈕
[alertA addButtonWithTitle:@"Cancelled"];
[alertA show];
//[alertA release];
}
來源:
程式開發與生活玩樂的隨手筆記
http://kkwinds.blogspot.com/2010/04/iphone_19.html
http://kkwinds.blogspot.com/2010/04/iphone.html
IPHONE SDK DEVELOP & PROGRAMMING TIPS
http://www.flyblog.info/catprogramming/73.html
來源:
程式開發與生活玩樂的隨手筆記
http://kkwinds.blogspot.com/2010/04/iphone_19.html
http://kkwinds.blogspot.com/2010/04/iphone.html
IPHONE SDK DEVELOP & PROGRAMMING TIPS
http://www.flyblog.info/catprogramming/73.html
[轉載] 幾個有關@property的屬性說明
@property是一個屬性訪問聲明,擴號內支持以下幾個屬性:
1、getter=getterName,setter=setterName,設置setter與getter的方法名2,readwrite、readonly,設置可供訪問級別
2、assign、setter方法直接賦值,不進行任何retain操作,為了解決原類型與環循引用問題
3、retain、setter方法對參數進行release舊值再retain新值,所有實現都是這個順序(CC上有相關資料)
4、copy、setter方法進行Copy操作,與retain處理流程一樣,先舊值release,再Copy出新的對象,retainCount為1。這是為了減少對上下文的依賴而引入的機制。
5、nonatomic,非原子性訪問,不加同步,多線程並發訪問會提高性能。注意,如果不加此屬性,則默認是兩個訪問方法都為原子型事務訪問。鎖被加到所屬對象實例級
轉自 CocoaChina 開發討論區
1、getter=getterName,setter=setterName,設置setter與getter的方法名2,readwrite、readonly,設置可供訪問級別
2、assign、setter方法直接賦值,不進行任何retain操作,為了解決原類型與環循引用問題
3、retain、setter方法對參數進行release舊值再retain新值,所有實現都是這個順序(CC上有相關資料)
4、copy、setter方法進行Copy操作,與retain處理流程一樣,先舊值release,再Copy出新的對象,retainCount為1。這是為了減少對上下文的依賴而引入的機制。
5、nonatomic,非原子性訪問,不加同步,多線程並發訪問會提高性能。注意,如果不加此屬性,則默認是兩個訪問方法都為原子型事務訪問。鎖被加到所屬對象實例級
轉自 CocoaChina 開發討論區
2012年3月23日 星期五
NSNotification 傳值
準備訊息
發送訊息
註冊觀察者
移除觀察者
範例下載
NSNotification *notification = [NSNotification notificationWithName:@"UserInfoNotify"
object:nil
userInfo:[NSDictionary dictionaryWithObjects:userInfoValues forKeys:userInfoKeys]];
發送訊息
[[NSNotificationCenter defaultCenter] postNotification:notification];
註冊觀察者
[[NSNotificationCenter defaultCenter] addObserverForName:@"UserInfoNotify"
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *notification) {
NSDictionary *dict = notification.userInfo;
}];
移除觀察者
[[NSNotificationCenter defaultCenter] removeObserver:self];
範例下載
2012年1月6日 星期五
Snakes & Ladders !
源自於印度的桌上遊戲,棋盤上除方格外,還會有梯子、蛇。
以骰子隨機決定棋子的步數,途中若抵達梯子或蛇的格子會移至其他格,以抵達終點為勝利。
Snakes & Ladders ! 1.3 更新
1.增加儲存遊戲/讀取遊戲功能
2.更改程式內的遊戲名稱圖片
3.對版面做些微調
“Snakes & Ladders !” for iPhone and iPad
http://itunes.apple.com/app/id489788712
以骰子隨機決定棋子的步數,途中若抵達梯子或蛇的格子會移至其他格,以抵達終點為勝利。
Snakes & Ladders ! 1.3 更新
1.增加儲存遊戲/讀取遊戲功能
2.更改程式內的遊戲名稱圖片
3.對版面做些微調
“Snakes & Ladders !” for iPhone and iPad
http://itunes.apple.com/app/id489788712
2011年8月5日 星期五
架設可點播的的音樂電台 foobar2000+Icecast2
網路上找的幾乎都是Winamp+插件來架設,不過我平常沒有使用Winamp,所以我想找foobar2000+插件來達成,有oddcast和edcast兩種,不過網站已經關掉,網路上的版本也沒有辦法搭配現在foobar2000的版本,最後找到Vorbis Streamer這個插件,搭配Icecast2就可以有自己的音樂電台囉!
必須要真實IP別人才連得進來,要不然只能區網自high
如果上傳不夠力,可考慮上傳到livedoor,但我不知道流量限制是多少
foobar2000 播放音樂的軟體,功能多、插件多
Vorbis Streamer foobar2000的插件,讓播放的音樂變成串流傳到網路上
Icecast2 架設多媒體串流伺服器,不確定影片可不可以
Request Http foobar2000的插件,讓大家可以線上點歌並播放
軟體安裝過程就不多說了,foobar2000的插件解壓縮要放在components資料夾下,Request Http的template隨你放,待會還要設定位置
Icecast 照以下設定
選擇"Edit Configuration"先做設定,請看下圖
串流密碼是串流時需要的密碼
管理帳號密碼是Icecast2的網頁管理系統
port預設值是8000,一般不需更改
編輯完後存檔後按"Start Server"
設定 Vorbis Streamer 插件
你會看到兩欄,右邊顯示你裝的所有插件,要移到左邊才會啟動
選取Vorbis Streamer並點"Configure selected"來做設定
Request http是點播插件等等會用到
基本上如圖設定不用改,其中Server Address,如果你foobar2000和Icecast2是在不同電腦才需要改。Encoder Password是在Icecast2中設定的串流密碼。如果設定無誤,並且Icecast2開啟伺服器以及foobar2000播放後Icecast2會接收到串流來源,並且顯示出串流連結,這連結用支援ogg的播放軟體即可開啟
顯示出該來源目前播放歌曲的相關資料,還有聽眾人數,同時串流來源可多個
接下來設定Request http
先設定template資料夾位置以及當沒有點播時的播放選擇,還有必須是公開的播放清單才會在點播裡。最後按下Start開啟點播系統,如果有更動過播放清單必須按Reconstruct index才會更新,這裡只講基本設定,至於More settings自己試試看吧。用瀏覽器開啟點播系統,網址是 http://ip:port/裡面有多種樣式可選擇,我自己比較喜歡Javascript version ( 2 column )
必須要真實IP別人才連得進來,要不然只能區網自high
如果上傳不夠力,可考慮上傳到livedoor,但我不知道流量限制是多少
foobar2000 播放音樂的軟體,功能多、插件多
Vorbis Streamer foobar2000的插件,讓播放的音樂變成串流傳到網路上
Icecast2 架設多媒體串流伺服器,不確定影片可不可以
Request Http foobar2000的插件,讓大家可以線上點歌並播放
軟體安裝過程就不多說了,foobar2000的插件解壓縮要放在components資料夾下,Request Http的template隨你放,待會還要設定位置
Icecast 照以下設定
選擇"Edit Configuration"先做設定,請看下圖
串流密碼是串流時需要的密碼
管理帳號密碼是Icecast2的網頁管理系統
port預設值是8000,一般不需更改
編輯完後存檔後按"Start Server"
設定 Vorbis Streamer 插件
你會看到兩欄,右邊顯示你裝的所有插件,要移到左邊才會啟動
選取Vorbis Streamer並點"Configure selected"來做設定
Request http是點播插件等等會用到
基本上如圖設定不用改,其中Server Address,如果你foobar2000和Icecast2是在不同電腦才需要改。Encoder Password是在Icecast2中設定的串流密碼。如果設定無誤,並且Icecast2開啟伺服器以及foobar2000播放後Icecast2會接收到串流來源,並且顯示出串流連結,這連結用支援ogg的播放軟體即可開啟
顯示出該來源目前播放歌曲的相關資料,還有聽眾人數,同時串流來源可多個
接下來設定Request http
先設定template資料夾位置以及當沒有點播時的播放選擇,還有必須是公開的播放清單才會在點播裡。最後按下Start開啟點播系統,如果有更動過播放清單必須按Reconstruct index才會更新,這裡只講基本設定,至於More settings自己試試看吧。用瀏覽器開啟點播系統,網址是 http://ip:port/裡面有多種樣式可選擇,我自己比較喜歡Javascript version ( 2 column )
2011年7月4日 星期一
訂閱:
文章 (Atom)





