網頁

2012年5月31日 星期四

加入Frameworks到你的專案內

【環境:xCode4.2 , ios5.1】
說明:此圖為加入音訊功能檔,AVFoundation.framework



網路檢測

20120613新增apple官網範例(使用方式略有差異)

【環境:xCode4.2 , ios5.1】
宣告:利用 UIDevice 的功能
說明:
Connectivity(.h .m)資料來源參考-掌握iPhone SDK 程式開發技巧
利用該原碼提供網路偵測的判斷,使用前須先挂載 SystemConfiguration.framework,挂載方式請參閱
引用方式[UIDevice cellularConnected][UIDevice wiFiConnected][UIDevice networkConnected]即可使用

功能執行:
1.利用淡入淡出視覺頁面


2.切換進入功能頁,點選按鈕可偵測網路....啓動語音或者視訊等相關功能



範例下載

<以下範例>
Connectivity.h
 
#import <SystemConfiguration/SCNetworkReachability.h>

//add SystemConfiguration Framework

@interface UIDevice (DeviceConnectivity)

+(BOOL)cellularConnected; 
+(BOOL)wiFiConnected;
+(BOOL)networkConnected;   

@end
Connectivity.m
#import "Connectivity.h"

#define EXTERNAL_HOST @"google.com"

@implementation UIDevice (DeviceConnectivity)

+(BOOL)cellularConnected{// EDGE or GPRS
  SCNetworkReachabilityFlags    flags = 0;
  SCNetworkReachabilityRef      netReachability = NULL;  
  netReachability     = SCNetworkReachabilityCreateWithName(CFAllocatorGetDefault(), [EXTERNAL_HOST UTF8String]);
  if(netReachability){
    SCNetworkReachabilityGetFlags(netReachability, &flags);
    CFRelease(netReachability);
  }
  if(flags & kSCNetworkReachabilityFlagsIsWWAN){
    return YES;
  }
  return NO;
}
+(BOOL)wiFiConnected{
  if([self cellularConnected]){
    return NO;
  }
  return [self networkConnected];
}
+(BOOL)networkConnected{
  SCNetworkReachabilityFlags     flags = 0;
  SCNetworkReachabilityRef       netReachability = NULL;
  BOOL                           retrievedFlags = NO;
  
  netReachability     = SCNetworkReachabilityCreateWithName(CFAllocatorGetDefault(), [EXTERNAL_HOST UTF8String]);
  if(netReachability){
    retrievedFlags      = SCNetworkReachabilityGetFlags(netReachability, &flags);
    CFRelease(netReachability);
  }
  if (!retrievedFlags || !flags){
    return NO;
  }
  return YES;
}
@end

2012年5月30日 星期三

NSLog

【環境:xCode4.2 , ios5.1】

說明:通常用來檢測某些值是否傳遞正確

<以下範例>
 
 /*
 * %@ 对象
 * %d, %i 整数
 * %u 无符整形
 * %f 浮点/双字
 * %x, %X 二进制整数
 * %o 八进制整数
 * %zu size_t
 * %p 指针
 * %e 浮点/双字 (科学计算)
 * %g 浮点/双字
 * %s C 字符串
 * %.*s Pascal字符串
 * %c 字符
 * %C unichar
 * %lld 64位长整数(long long)
 * %llu 无符64位长整数
 * %Lf 64位双字
 */
 NSString *string = @"N11 studio";
 NSLog(@"%@",string);

 //其他特殊
 //顯示出sizeof的大小
 NSString *stringValue = input;/*the UTF8 string parsed from xml data*/
 Byte inputData[[stringValue  lengthOfBytesUsingEncoding:NSUTF8StringEncoding]];//prepare a Byte[]
 [[stringValue dataUsingEncoding:NSUTF8StringEncoding] getBytes:inputData];//get the pointer of the data
 size_t inputDataSize = (size_t)[stringValue length];
 NSLog(@"%zd",sizeof(inputDataSize));

 //顯示出bool的方式
 NSLog(@"BOOL = %@\n", (boolVar ? @"YES" : @"NO")); 


 //其他特殊的顯示...若要取得某些範圍
 //NSStringFromCGPoint  
 //NSStringFromCGSize  
 //NSStringFromCGRect  
 //NSStringFromCGAffineTransform  
 //NSStringFromUIEdgeInsets
 //比如
 NSLog(@"rect1: %@", NSStringFromCGRect(rect1)); 

擷取simulator螢幕的利器

【環境:xCode4.2 , ios5.1】

iOS-Simulator Cropper


這次介紹這個小工具,總之就是相當好用....附加相當多的選項
關於載點,就請到官網下載吧




可以選擇儲存的方式如下....上面還細心幫你分類...提示你若是放在connect上,用的規格,儲存的方式也是.png檔,大小就是你螢幕的大小

也可以拍照成像這樣的形式,像是做簡報相當好用,一整個就是精緻+方便


2012年5月24日 星期四

SKU number

建立好你的app之後準備上傳,到 iTunes Connect 中,會遇到填寫SKU number

SKU number : Stock Keeping Unit (A unique number used to identify the app you are adding.

輸入這個只要是用於銷售狀況查詢上的區分多個app用的名稱,假如和其他app名稱重複,則你可能會搞不懂哪個是哪個。
主要是給管理者看銷售狀況的一個標籤。

唯一要注意的是,SKU number 在 iTunes Connect 裡完成 Add New App 流程之後就不能改

*注意送審過後和在connect上註冊新的App,所限制不能更改的部分,是不同的,送審完畢上架後,也有其他不能更改的設定

2012年5月22日 星期二

在xCode中設定你的Code Signing Identity

【環境:xCode4.2 , ios5.1】

xCode必須設定,從develop中下載的認證,去設定該認證為實機測試還是發佈後,才可以去發佈或者實機測試

Setting Your Code Signing Identity

When you build your app to run it on a device, Xcode signs it with a development certificate (also known as a code signing identity) stored on your keychain. To learn how to obtain and install development certificates, see “Provisioning a Device for Development.”
The Code Signing Identity build setting specifies the provisioning profile and code signing identity Xcode uses to sign your binary. Xcode looks for code signing identities in your default keychain.
image: ../art/myapp_project-code_signing_identity_build_setting.jpg
The possible values for the Code Signing Identity build setting are:
  • Don’t Code Sign. Choose this option to build only for a simulator.
  • Automatic Profile Selector. Choose an option under this selector to select a provisioning profile whose name starts with “iPhone Developer” or “iPhone Distribution.”
  • Specific Profile. Choose the code-signing identity under a specific provisioning profile when your app requires special entitlements (see “Provisioning Your Device for Specialized Development”). Expired or otherwise invalid provisioning profiles are dimmed and cannot be used.
    Figure 3-2 shows a set of options for the Code Signing Identity build setting with a provisioning profile for specialized development selected.
    Figure 3-2  Code Signing Identity options with a specialized provisioning profile selected
Project templates are configured to use the automatic selector to set the signing identity. You need to change the value of the Code Signing Identity build setting only when your app uses a specialized provisioning profile. See “Replacing an Expired Certificate” for details.

Specifying the Runtime Environment

Three aspects of your app’s runtime environment are: where your app runs, what app-data is placed in its sandbox, and what location or track the Core Location framework reports to it.

Specifying the Run Destination

Before building your app, Xcode has to know where you want to run it. You specify this run destination in the Scheme toolbar menu. Using that menu you can switch from running your app in a simulator to running it on your device to, for example, test the device performance of your app.
When you plug into your Mac a device with a valid provisioning profile, its name and the iOS version it’s running appear as an option in the Scheme toolbar menu. Use the menu to switch between running your app on a device or in a simulator.
image: ../art/scheme_menu.jpg

2012年5月21日 星期一

bundle id , bundle seed id , application id?



application id = bundle seed id + bundle id


這個是ios用來識別每一個開發者的軟體的識別碼


W64K7TYEZ9 此10個字元為bundle seed id , 這可以在develop portal 中,建立app id時,可選是用team id or your App ID
Use your Team ID or select an existing Bundle Seed ID for your App ID.
If you are creating a suite of applications that will share the same Keychain access, use the same bundle Seed ID for each of your application's App IDs.


Bundle Identifier (App ID Suffix) = com.applicationName.abc


所以     App ID = Bundle Seed ID (App ID Prefix) + Bundle Identifier (App ID Suffix)


此種方法可以確保應用程式的id是唯一,其中Bundle Identifier (App ID Suffix),可讓使用者自行建立,產品分類規劃。



iphone ios實機測試流程


【環境:ios開發者認證中心developer web
要拿到開發者的profile,才能實機測試的profile和獲取發佈的profile

1.首先要在用來開發的電腦上建立Certificate Signing Request(CSR)
開啟Keychain Access(鑰匙圈存取),在功能表中選擇Preferences(偏好設定),把OSCP和CRL設定為off。

2.選擇Keychain Access -> Certificate Assistant ->Request a Certificate from a Certificate Authority,該注意的是選取的時候,選項後方不可以有<private key>



3.輸入e-mail、姓名,該注意的是此地方要輸入你申請開發者中心時一樣的資料,CA一欄不用填,選擇儲存到硬碟和指定秘鑰配對記錄


4.然後到最後儲存<CertificateSigningRequest>

5.到認證中心下載WWDR,上傳建立好的<CertificateSigningRequest>到認證中心


6.批准剛剛上傳的CertificateSigningRequest後,回到剛剛的頁面下載該電腦用戶的Certificate,並點兩下安裝。此為用戶的公開金鑰。

7.接下來就把測試機器的UDID添加到Devices中,UDID的建立方法很多種,可以透過xcode建立,也可以直接建立。

8.建立App ID,這個主要用作限制組內不同開發人員對不同專案的profile的使用權。這邊申請的ID和之後要測試的xcode中的info資訊要相同。
ex: com.companyName.appName
值得注意的是若最後加上*,此為萬用字元,則此ID適用於多個專案。
ex: com.companyName.*

在 Xcode 裡設定專案的 Bundle Identifier:
     選取專案 > Targets下專案名稱 > Info 頁籤 >  
xCode

Description: 對 App ID 的描述, 使用英文字母. 

Bundle Seed ID (App ID Prefix): App ID 的前綴詞, 自動產生.
Bundle Identifier (App ID Suffix): App ID 的字尾部分.
Developer




9.接下來建立Provisioning,在Portal畫面中,按下Provisioning,在Development標簽下,按下New Profile,之後建立相關的資料。

10.安裝剛剛建立好且通過admin的認證後,一樣下載後直接點兩下安裝,此時xCode中的Oganizer就會打開,就可看到你剛剛安裝的認證檔的資料。

11.隨後在xCode中選擇好simulation的版本和更新好專案中的App ID,就可以直接執行測試摟。
詳細設定可以參考<在xCode中設定你的Code Signing Identity>


2012年5月20日 星期日

NULL or nil?

In Cocoa both of them are typedef to zero. nil is an object pointer, whereas NULL is a c pointer.  If you want to set char * to 0 then you would set it to NULL and if you want to set a view controller to 0 then you would set it to nil. Cocoa also gives us another typedef  called "Nil" (notice the case) which is class pointer. Now you know when to use the correct null pointer.

【iTunes Connect】新建iphone app須準備事項


【環境:Dev GUIDE 7.4iTunes Connect

說明:
這是以前我看7.3的文件資料,詳細的檔案請參閱上方最新官方文件,以下的一些流程,先弄好,或許比較不會上傳時還手忙腳亂,資料缺東缺西,等有機會再把官方文件翻譯。

基本上這是你決定要開發app時,就要想好的東西,至少上架前要準備好
1.決定名稱(中/英)
2.決定關鍵字
IMPORTANT:  If you enter a keyword that is trademarked or references another app’s name or company name, your app may be removed from the App Store.
3.產品分類,關於分類裡面有分很多種,其實我也搞不太懂==
4.Copyright*

iTunes Connect建立app基本資料後(程式尚未上傳)不可更改的部份有以下
1.app name
2.版本序號
3.分級
4.首要類別
5.次要類別
6.關鍵字
7.512*512的圖形

主要類別


次要類別



上傳app前須準備清單
1.512*512 jpeg的圖 72dpi /RGB / 平滑 / 非半透明
2.57*57 png
3.螢幕截圖4張(320x460)or(320x480)差別在於是否全螢幕
4.基本上,上傳時要你建立描述的文字,空白其實沒有關係,或者打幾個英文字,不然怕因中文碼的關係,系統存到資料庫變成亂碼,那些審查人員會看成亂碼。

注意你的57icon和512icon必須雷同,否則會被dev center打回票

==以下為官方說明文件截取==
Dev GUIDE 7.3
事前準備
app binary 
iOS binaries: Includes 57px and an optional 114px hi-res icon for iPhone and iPod touch or a 50px and72px icon for iPad 
Mac OS X binaries: Includes at least a 512x512px and 128x128px icon
large 512px icon for use on the desktop App Store (for iOS apps only)
screenshot(s) 
contract information 
export compliance information
app metadata Optional items to prepare include:
additional screenshots 
localized metadata for the sale of your app in other countries 
promotional graphics

所以就全部用成png檔吧,省時方便,不過png和jpeg之類的,如果是專業的影像人才應該會很care吧。

至於如何在xCode中設定icon的方式,請參考xCode4.2建立app icon


xCode4.2建立app icon

【環境:xCode4.2 , ios5.1】
說明:如何更換自己的app icon,並選擇是否要對icon加上預設的glass,4.2版本似乎移除了info.plist的檔案,不過更換方式更方便。把圖片放上去後,重新執行就可以看到效果了。

如圖:
事前準備兩張圖片,57x57 & 114x114,滑鼠久放在那兩個空位上可以看到原因,對那兩個空格按右鍵,可以得到「select file」的選擇鍵上傳。


























至於若你的icon本身已經有了glass的話,就可以把內建的給取消掉,基本上我記得以前看原始文件有說,若是加兩層(自己icon本身已有+系統加上),透明度太高的話,好像會被apple打回票,所以還是小心點摟~

2012年5月19日 星期六

(ios) NSString (六)【子字串的相關處理】

【環境:xCode4.2 , ios5.1】
1.說明:From:從指定位置到結尾。To:從開頭到指定位置。WithRange:傳回一個範圍和NSRange並用

 
- (NSString *)substringFromIndex:(NSUInteger)from;
- (NSString *)substringToIndex:(NSUInteger)to;
- (NSString *)substringWithRange:(NSRange)range;//Hint: Use with rangeOfComposedCharacterSequencesForRange: to avoid breaking up composed characters


<以下範例>
 
    NSString *string1 = @"this blog is n11 studio";
    NSString *string2 = [string1 substringFromIndex:13];
    NSLog(@"%@",string2);
    //the answer is "n11 studio" 

2.說明:Pre:判斷接收訊息的物件開頭是否為aString。Suf:判斷結尾是否是aString
- (BOOL)hasPrefix:(NSString *)aString;
- (BOOL)hasSuffix:(NSString *)aString;

(ios) NSString (五)【compare:】

【環境:xCode4.2 , ios5.1】
宣告:-(NSComparisonResult)compare:(NSString *)string1 option:(NSStringCompareOptions)mask range:(NSRange)range
名稱:用compare對字串中的字元進行逐一比較
說明:NSComparisonResult傳回的類型(註一),option為一個遮罩參數(註二),range表示要比較的範圍(註三

<以下範例>
 
    NSString *string1 = @"this blog is n11 studio";
    NSString *string2 = @"n11 studio";
    NSRange myRange;
    myRange.location = 13;
    myRange.length = 10;
    NSComparisonResult result = [string1 compare:string2 options:NSCaseInsensitiveSearch range:myRange];
    if(result == NSOrderedSame)
    {
        NSLog(@"it is the same");
    } 

(ios) NSString (四)【計算字串的字元個數】

【環境:xCode4.2 , ios5.1】
方法宣告:- (void)length
名稱:計算字串的字元個數
語法:[string1 length]
說明:傳回被呼叫字串中的字元個數

<以下範例>
 
    NSString *string1 = @"n11 studio";
    int stringLength = [string1 length];
    NSLog(@"%d",stringLength);

(ios) NSString (三)【初始化】

【環境:xCode4.2 , ios5.1】 名稱:
語法:initWithString: initWithFormat:
說明:字串的初始化方法,有些時候你可能需要將字串初始化並加上其他字串,用這個方法可以很快的使用,省去很多行的初始化
initWithString:
initWithFormat:
<以下範例>
 
    NSString *string1 = @"this ";
    NSString *string2 = [[NSString alloc] initWithFormat:@"is "];
    NSString *string3 = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%@%@n11 studio",string1,string2]];
    NSLog(@"%@",string3); 

(ios) NSString (二)【stringByAppendingString:】

【環境:xCode4.2 , ios5.1】
名稱:字串相加
語法:[string1 stringByAppendingString:string2]
說明:這個的好處就是....可以一直無限加下去

<以下範例>
    NSString *string1 = @"n";
    NSString *string2 = [[NSString alloc] initWithFormat:@"studio"];
    string1 = [[string1 stringByAppendingString:@"11 "] stringByAppendingString:string2];
    NSLog(@"%@",string1);
    //the answer is "n11 studio"  

(ios) NSString (一)【isEqualToString:】

【環境:xCode4.2 ,  ios5.1】

名稱:比較字串
語法:[string1 isEqualToString:string2]

說明:有時我們想檢查這兩個字串的旗標,是否是同一個,則可以使用 ==。
若想察看兩個字串是否代表同一個數字時,請用isEqualToString:


<以下範例>

    NSString *string1 = @"n11 studio";
    NSString *string2 = [NSString stringWithFormat:@"n11 %@",@"studio"];
    //ex1
    if([string1 isEqualToString:string2])
    {
        NSLog(@"相同");
    }
    else
    {
        NSLog(@"不相同");
    }
    //ex2
    if(string1 == string2)
    {
        NSLog(@"相同");
    }
    else
    {
        NSLog(@"不相同");
    }
    //ex3
    if(string1 == string1)
    {
        NSLog(@"相同");
    }
    else
    {
        NSLog(@"不相同");
    }

2012年5月12日 星期六

HamiCloud


現在整合性的服務很多,這類型的服務,可以用在家庭、小型企業、團體均很好用,若是商業機密之類的,可能要斟酌一下,以前的年代大家都用ftp比較多吧,不過ftp還是有ftp的好處。

2012年5月7日 星期一

任何一個功能或者系統


或許應該達到以下的幾個規範,或者對於整個MVC系統的維護,架構,擴編均有很大的幫助
  • 動態實例化(dynamic instantiation):
  •  在系統中,元件只有在請求時才會載入並執行,而不是放在global等待使用。除了最小的核心,系統對於所需要的資源不做任何假設。所以預設的系統是非常輕量化的。由HTTP請求所觸發的事件,以及你所設計的控制器(controller)及檢視(view)會決定要執行什麼。
  • 鬆散耦合(loose coupling):
  •  耦合是系統中元件互相依賴的程度。越少相互依賴的元件,系統的重用以及彈性會越好。
  • 元件單一性(component singularity):
  •  單一性是元件有狹隘的用途的程度。系統架構中,每個類別以及它的功能是高度自主的,以便達到最大的效用。

Coda初體驗

第一次使用Coda,一直在尋找合適的編輯器,雖然我一向不怎麼在乎編輯器這種東西,畢竟對我來說就是硬coding就對了,不過好的編輯器,可以開發快速,這對我來說或許也是個幫助


<未完待續>

mac app的中文化

http://www.macuknow.com/node/1168

這是一篇網路上的分享文章
改天來測試看看
自己動手做中文化

下面這個連結是pdf的教學範本

教學範本.pdf

MAMP pro

第一次的使用MAMP在mac上架站,一開始都很順利,因為包含MAMP的設定相當簡單,唯一比較特別的就是用no-ip的設定吧,之後有機會去試試Dynamic DNS的設定,還有另一點須注意的就是,當你用無線ip分享器,之類的網路,若沒有設定好,可能外部無法連到本機的網頁apach,這是相當基礎的錯誤,以前也遇過,不過忘了,換成直接用實體線路接上中