顯示具有 Xcode 標籤的文章。 顯示所有文章
顯示具有 Xcode 標籤的文章。 顯示所有文章

2016年5月23日 星期一

0523 Xcode 自動累加BUILD number

https://gist.github.com/sekati/3172554
每次builder 自對累加

# @desc Auto-increment the build number every time the project is run.
# @usage
# 1. Select: your Target in Xcode
# 2. Select: Build Phases Tab
# 3. Select: Add Build Phase -> Add Run Script
# 4. Paste code below in to new "Run Script" section
# 5. Drag the "Run Script" below "Link Binaries With Libraries"
# 6. Insure that your starting build number is set to a whole integer and not a float (e.g. 1, not 1.0)
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"

每次匯出 自動累加

# @desc Auto-increment the version number (only) when a project is archived for export.
# @usage
# 1. Select: your Target in Xcode
# 2. Select: Build Phases Tab
# 3. Select: Add Build Phase -> Add Run Script
# 4. Paste code below in to new "Run Script" section
# 5. Check the checkbox "Run script only when installing"
# 6. Drag the "Run Script" below "Link Binaries With Libraries"
# 7. Insure your starting version number is in SemVer format (e.g. 1.0.0)
# This splits a two-decimal version string, such as "0.45.123", allowing us to increment the third position.
VERSIONNUM=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${PROJECT_DIR}/${INFOPLIST_FILE}")
NEWSUBVERSION=`echo $VERSIONNUM | awk -F "." '{print $3}'`
NEWSUBVERSION=$(($NEWSUBVERSION + 1))
NEWVERSIONSTRING=`echo $VERSIONNUM | awk -F "." '{print $1 "." $2 ".'$NEWSUBVERSION'" }'`
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $NEWVERSIONSTRING" "${PROJECT_DIR}/${INFOPLIST_FILE}"
http://fstoke.me/blog/?p=3987 
使用範例

如何幫App加自動Build Number機制

雖然很簡單,但寫起來以免忘記…

1. 點選project file(xxx.xcodeproj)
2. 點選Xcode上方Toolbar的選項: Add Build Phase -> Add Run Script Build Phase
3. 在下方黑色script輸入框內輸入:
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
4. 修改General -> Build輸入框裡的文字為一個數字
這樣就好了。之後每次build,那個數字就會自累加。

0523 cocos2d-x 版本取得 Version builder

參考下方範例 得出正確作法:
1.此兩個檔案依定要透過Xcode 開啟!檔案總館看不倒
位於專案中的cocos2d/build/cocosd_libs.xcodeproj/ platform/ios/CCApplication-ios.h
 class CC_DLL Application : public ApplicationProtocol 增加
    const char *getAppVersion();
    const char *getBuild();
2.
cocos2d/build/cocosd_libs.xcodeproj/ platform/ios/CCApplication-ios.mm
//取得IOS 版本
float Application::getSystemVersion() {
    return [[UIDevice currentDevice].systemVersion floatValue];
}
const char* Application::getAppVersion()
{
    return [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] UTF8String];
}
const char* Application::getBuild()
{
    return [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] UTF8String];

}
3. 使用 class/AppDelegate.cpp 
    printf("ios Vsersion=%1.1f\n",getSystemVersion());

    printf("Appversin = %s.%s\n",getAppVersion(),getBuild());

參考文獻
====================================================================
Q:在coco2d中可以直接使用: 
(AppController *)[[UIApplication sharedApplication] delegate]; 這樣的方法 
但是在cocos2d-x中,這樣就不行了,有什麼理法可以得到AppController 
也就是說怎麼樣c++的代碼和本地Object-c相互調用

A:
將文件後綴名修改為mm,進行混編 
=========================================
以下OC 跟SWIFT 尚未找到呼叫範例
switf 範例 
extension UIApplication {

class func appVersion() -> String {
return NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as! String
}

class func appBuild() -> String {
return NSBundle.mainBundle().objectForInfoDictionaryKey(kCFBundleVersionKey as String) as! String
}

class func versionBuild() -> String {
let version = appVersion(), build = appBuild()

return version == build ? "v\(version)" : "v\(version)(\(build))"
}
}
========================================
Object CC 範例
@implementation UIApplication (AppVersion)

+ (NSString *) appVersion
{
return [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleShortVersionString"];
}

+ (NSString *) build
{
return [[NSBundle mainBundle] objectForInfoDictionaryKey: (NSString *)kCFBundleVersionKey];
}

+ (NSString *) versionBuild
{
NSString * version = [self appVersion];
NSString * build = [self build];

NSString * versionBuild = [NSString stringWithFormat: @"v%@", version];

if (![version isEqualToString: build]) {
versionBuild = [NSString stringWithFormat: @"%@(%@)", versionBuild, build];
}

return versionBuild;
}

@end
==============================================
取得ios 版本範例
The way I implemented in cocos2d-x 3.4, is to add the following method in CCApplication-ios.mm
float Application::getSystemVersion() {
    return [[UIDevice currentDevice].systemVersion floatValue];
}
Add this to CCApplication-ios.h
/** Get iOS version */
static float getSystemVersion();
And call it anywhere by using
float systemVersion = Application::getSystemVersion();
================================================

CFBundleVersion與CFBundleShortVersionString


[cpp] view plain copy
  1. string CCDevice::getVersionName()  
  2. {  
  3.     return [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] UTF8String];  
  4. }  
[cpp] view plain copy
  1. NSString *developmentVersionNumber = [bundle objectForInfoDictionaryKey:@"CFBundleVersion"];  


CFBundleVersion,標識(發佈或未發佈)的內部版本號。這是一個單調增加的字符串,包括一個或多個時期分隔的整數。
CFBundleShortVersionString  標識應用程序的發佈版本號。該版本的版本號是三個時期分隔的整數組成的字符串。第一個整數代表重大修改的版本,如實現新的功能或重大變化的修訂。第二個整數表示的修訂,實現較突出的特點。第三個整數代表維護版本。該鍵的值不同於「CFBundleVersion」標識。

版本號的管理是一個謹慎的事情,希望各位開發者瞭解其中的意義。

比較小白,更新應用的時候遇到版本號CFBundleShortVersionString命名的錯誤,導致無法更新,後來看了文檔研究下發現是這樣,希望給不瞭解的人以啟示;

圖片裡的 Version 對應的就是CFBundleShortVersionString (發佈版本號 如當前上架版本為1.1.0  之後你更新的時候可以改為1.1.1)
          Build 對應的是 CFBundleVersion(內部標示,用以記錄開發版本的,每次更新的時候都需要比上一次高 如:當前版本是11  下一次就要大於11 比如 12,13 ....10000)

From:http://blog.sina.com.cn/s/blog_8c87ba3b0101a1gd.html

2016年4月27日 星期三

0427 Xcode 環境編輯套件 安裝教學跟推薦

http://www.cnblogs.com/Bob-wei/p/4546498.html

Xcode插件

1.安裝Alcatraz
https://github.com/alcatraz/Alcatraz
「安裝」
終端輸入:
curl -fsSL https://raw.github.com/alcatraz/Alcatraz/master/Scripts/install.sh | sh
或者從 https://github.com/alcatraz/Alcatraz.git clone然後用Xcode編譯即可。

「卸載」
刪除插件:
rm -rf ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins/Alcatraz.xcplugin
刪除緩存數據:
rm -rf ~/Library/Application\ Support/Alcatraz

2.啟動Xcode,菜單命令Window - Package Manager(或者Command+Shift+9)
強烈推薦插件:
FuzzyAutocomplete              模糊輸入自動完成提示。愛護小手指必備。
OpenInSublimeText              增加用Sublime Text打開文檔的菜單項:Editor > Open In Sublime Text。
                               為方便使用,可設置快捷鍵:在「系統偏好設置」-「鍵盤」-「快捷鍵」-「應用快捷鍵」,點「+」,輸入:
                               應用程序:選擇「Xcode.app」,菜單標題輸入:「Open In Sublime Text」,快捷鍵:「⌥⌘O」
Xcode_copy_line                未選中文本情況下,按⌃X、⌃C或⌃V可對整行剪切、複製和粘貼操作。
XAlign                         選中一組賦值或字段聲明語句,按⇧⌘X可快速對其格式化選中代碼。在定義枚舉時候,對齊名字的值時特別好用。
AdjustFontSize                 按⌘-和⌘=改變字號大小。
VVDocumenter-Xcode             輸入///快速添加代碼文檔註釋。然後可在Xcode右側的Quick help inspector中查看自己編輯的文檔註釋。
DXXcodeConsoleUnicodePlugin    轉換Xcode控制台中Unicode字符編碼為可顯示的字符。在輸出包含漢字的JSON時特別有用。
                               1.按⌥c轉換剪貼板;
                               2.Edit菜單中勾選ConvertUnicodeInConsole,console將自動轉換。
OMQuickHelp                    讓Option+Click轉到Dash文檔查看。Dash的Xcode文檔,建議從 
                               https://developer.apple.com/library/downloads/docset-index.dvtdownloadableindex
                               中搜索下載。下載後獲得dmg文件,載入後執行pkg按嚮導安裝。全部安裝完成後,到 / 目錄將所有 .docset 移動到
                               ~/Library/Developer/Shared/Documentation/DocSets
                               然後在Dash的設置-Docsets,點下面的Rescan按鈕,重新掃瞄來更新和優化文檔。

推薦插件:
CLangFormat                    Edit > CLang Fromat 格式化代碼風格。
DerivedData Exterminator       在Edit菜單中提供清理Xcode換乘目錄的功能。
GitDiff                        按⌘,在Text Editing中勾選Line Number,每次保存代碼都會在行號位置用顏色顯示git的變化。
HOStringSense                  方便編輯字符串。
JumpMarks                      首先使編輯器顯示行號。按⌥⇧[0-9]創建標籤,按⌥[0-9]跳到標籤位置,按⌥[或⌥]跳到上一個或下一個標籤位置。
KSImageNamed                   在輸入[UIImage imageNamed:]時會出現一個資源圖像列表。
Lin                            在輸入[NSLocalizedString(@"", <#comment#>)]時會出現一個本地化列表。
MCLog                          讓Log窗口可以實時篩選輸出內容。但是很不穩定,不建議安裝,發生過的問題:編輯器無法中文、啟動Xcode即崩潰、與XcodeColors衝突。
OMColorSense                   在UIColor或NSColor代碼中顯示可視化的顏色,點擊它會出現顏色窗口。
Peckham                        在代碼編輯器任意位置按⌃⌘P顯示一個#import列表。
RTImageAssets                  File > ImageAssets 來生成App Icon,在圖像資源編輯界面,右鍵圖像可補全不同分辨率圖像,見前面菜單的Settings。
SCXcodeMinimap                 使代碼編輯器滾動條編程minimap
SCXcodeSwitchExpander          在輸入switch語句時候自動生成case。
XcodeColors                    使調試輸出框文字能支持不同的顏色。可以自定義配置輸出顏色或者結合CocoaLumberjack框架。(同時安裝MCLog將不能正確顯示顏色)
XVim                           Vim鍵盤映射。
ZLGotoSandbox                  File > Go to Sandbox!可用Finder打開模擬器中當前App的沙盒目錄。

強烈推薦主題:
Tomorrow                       https://github.com/chriskempson/tomorrow-theme


3.修復某些不支持最新版本Xcode的插件:為插件配置文件的兼容性設置添加新Xcode的DVTPlugInCompatibilityUUID
(1)終端輸入:
defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID
會顯示當前Xcode的UUID,如:7FDF5C7A-131F-4ABB-9EDC-8C5F8F0B8A90
(2)終端輸入:
open ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins/
open ~/Library/Developer/Xcode/Plug-ins
可出現Finder顯示的Xcode插件目錄
(3)選擇這個不工作的插件,右鍵-顯示包內容,打開 Contents 目錄,雙擊 Info.plist,
展開數組:DVTPlugInCompatibilityUUIDs,添加第一步獲得到的Xcode UUID(7FDF5C7A-131F-4ABB-9EDC-8C5F8F0B8A90),
保存,關閉文件。
(4)重新啟動Xcode,加載插件。

一條命令批量更新DVTPlugInCompatibilityUUID
find ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins -name Info.plist -maxdepth 3 | xargs -I{} defaults write {} DVTPlugInCompatibilityUUIDs -array-add `defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID`

find ~/Library/Developer/Xcode/Plug-ins -name Info.plist -maxdepth 3 | xargs -I{} defaults write {} DVTPlugInCompatibilityUUIDs -array-add `defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID`



4.手動刪除插件
open ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins
open ~/Library/Developer/Xcode/Plug-ins
刪除不用的插件文件後,重啟Xcode即可。

cocos2dx-lua 建立滑鼠監聽

重要關鍵字  EVENT_MOUSE_SCROLL addEventListenerWithSceneGraphPriority      if IsPc() then --建立滑鼠監聽         local listener = cc.EventListenerMouse...