2012年8月30日 星期四

Variable argument lists in Cocoa

http://cocoawithlove.com/2009/05/variable-argument-lists-in-cocoa.html


還沒有實作  等等試試看!



=2012/09/07

這個確實還蠻有用的,在包自己某些常用的 library 時

用法跟 C語言的差不多

一樣可能會需要結尾判斷字元

物件通常用nil

int可以用-1之類的 (depend on 應用)



- (void)setContentByAppendingStrings:(NSString *)firstArg, ...
{
    NSMutableString *newContentString = [NSMutableString string];
    va_list args;
    va_start(args, firstArg);
    for (NSString *arg = firstArg; arg != nil; arg = va_arg(args, NSString*))
    {
        [newContentString appendString:arg];
    }
    va_end(args);
     
    [contents autorelease];
    contents = [newContentString retain];
}



iOS 的一些觀念

http://popcornylu.blogspot.tw/search/label/iOS


有空來看看別的人文章!


2012年8月29日 星期三

Xcode Build version

http://www.imthi.com/blog/programming/auto-increment-build-number-date-in-xcode-iphone-project.php


自動增加其實是有必要的

不過要配合daily build 之類的機制....




2012年8月28日 星期二

install LLVM

http://stenlyho.blogspot.tw/2009/04/llvm.html


現在用不到

不過還蠻有趣的!

[人] 臥龍三小

http://www.ols3.net/

臥龍三小

以前看過他蠻多文章的....!

2012年8月27日 星期一

Simple iOS audio playback

http://gregheo.com/blog/ios/simple-audio/


說來慚愧

寫了一段時間的IOS了  現在才大概知道怎麼撥簡短的聲音+震動

XD


// need this include file and the AudioToolbox framework
#import <AudioToolbox/AudioToolbox.h>

// also need an instance variable like so:
// SystemSoundID sound1;

NSURL *soundURL = [[NSBundle mainBundle] URLForResource:@"sample"
                                          withExtension:@"caf"];
AudioServicesCreateSystemSoundID((CFURLRef)soundURL, &sound1);
AudioServicesAddSystemSoundCompletion(sound1, NULL, NULL, systemAudioCallback, NULL);
AudioServicesPlaySystemSound(sound1); // or...
AudioServicesPlayAlertSound(sound1);
void systemAudioCallback(SystemSoundID soundId, void *clientData)
{
    NSLog(@"System sound finished playing!");
}
AudioServicesRemoveSystemSoundCompletion(sound1);    
AudioServicesDisposeSystemSoundID(sound1);

如何偵測手機是否JB



http://iosdevelopersnote.blogspot.tw/2012/02/jb.html




這篇的討論是用幾個常見 JB 過的行為來偵測是不是 JB 了,而沒辦法提供一個 100% 肯定的解決方法。首先我們來看一下 JB 過的 iOS 會有那幾個特色?
  1. 會有 Cyndia 這個 App
  2. 會需要背景執行
  3. info.plist 的SignerIdentity會被變動
我們就上面三點來假設都是 JB 需要做的行為,如果我們取得這些行為之後留下來的證據,就可以假設此手機是被 JB 了。我必需要再強調一次,這篇文章的行為我都還沒有真正測試過,只是收集網路上和書上的例子寫成,還請大家補充。
如何檢查此手機是不是安裝了 Cydia
NSString *filePath = @"/Applications/Cydia.app";
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
// 檢查是不是有 Cydia 這個程式
}
一般來說 iOS 現在是多工,方便切換程式而不是像 Mac 或 PC 作業系統的背景執行,通常 JB 後會把背景執行這個功能打開就會用到 fork() 這個指令,所以檢查有沒有背景執行的功能(fork())就可以知道有沒有 JB。
int result = fork();
if (result > 0) {
     NSLog(@"JBed");
}else{
     NSLog(@"NO JB");
}

2012年8月23日 星期四

客戶需求

http://www.cocoachina.com/gamedev/designer/2012/0823/4636.html


“如果我問我的用戶,他們只會說要一匹更快的馬。”—亨利•福特(Henry•Ford,1863—1947)


2012年8月21日 星期二

Test-Driven Development,測試驅動開發


有點興趣
http://registrano.com/events/429374

活動時間:2012/08/28 7:30pm 開始,6:30pm 開始入場


Ref

http://en.wikipedia.org/wiki/Test-driven_development



http://ithelp.ithome.com.tw/question/10081081
上面這篇有反面意見


====================================

原本注意到的是 我開始想完 Unit Test

然後發現了這個活動

活動介紹裡面有一段文字是吸引我的



近年來敏捷開發已漸漸由很多公司所採納,其中重要的基礎便需要自動化測試輔助;
講者近來使用TDD方式開發獲益良多;尤其最近在研究小型裝置開發時,

不過反面意見卻覺得不適用於 敏捷式開發

第一次自幹作業系統核心就上手



http://www.youtube.com/watch?v=5aaHm9VImVE

真的太厲害了  orz

2012年8月19日 星期日

取得 runtime 時,所有的class?!



擷取 GHUnit 裡面的code....


- (NSArray *)loadAllTestCases {
  NSMutableArray *testCases = [NSMutableArray array];

  int count = objc_getClassList(NULL, 0);
  NSMutableData *classData = [NSMutableData dataWithLength:sizeof(Class) * count];
  Class *classes = (Class*)[classData mutableBytes];
  NSAssert(classes, @"Couldn't allocate class list");
  objc_getClassList(classes, count);
  
  for (int i = 0; i < count; ++i) {
    Class currClass = classes[i];
    id testcase = nil;
    
    if ([self isTestCaseClass:currClass]) {
      testcase = [[currClass alloc] init];
    } else {
      continue;
    }
    
    [testCases addObject:testcase];
  }
  
  return [testCases sortedArrayUsingFunction:ClassSort context:NULL];
}

iOS Unit Test

http://furnacedigital.blogspot.tw/2011/02/unit-test.html


http://www.raywenderlich.com/3716/unit-testing-in-xcode-4-quick-start-guide


該學的還是要趕快學一學!




http://blog.xebia.com/2011/03/23/ios-xcode-4-ghunit-mobile-tddcontinuous-testing-part-2-of-n/


原本在猶豫要用原生的 OCUnit  還是  GHUnit

上面這篇講到了一個我care的點,

OCUnit 不能再實機上跑.....

經過測試  是乎真的是這樣....

那這樣....可能還是會投向第三方的懷抱吧orz



https://github.com/gabriel/gh-unit

http://gabriel.github.com/gh-unit/

2012年8月17日 星期五

2012年8月8日 星期三

cocoaheads

http://cocoaheads.tw/


某人較我要去參加聚會

或許這個聚會的形式看起來不錯

.....


不過要改一下去台北的時間了@@



https://groups.google.com/forum/?fromgroups#!topic/cocoaheadstw/c-ewkelCbWU%5B1-25%5D

Git something


http://ihower.tw/blog/archives/2591/

http://gitx.frim.nl/


http://www.mrmu.com.tw/2011/05/06/git-using-dropbox-as-server/

http://www.mrmu.com.tw/2011/05/06/git-tutorial-for-beginner/



!!!

http://ihower.tw/blog/posts/

2012年8月5日 星期日

Creating a Static Framework in Xcode 4 (轉)

2012/10/09

   Xcode 4.5.1 似乎不吃這個.....

   先用回 lib 好了....之後再研究包裝的方法


2012/08/17

實驗過下列的幾總方法

還是
https://github.com/kstenerud/iOS-Universal-Framework/
http://code.google.com/p/ios-static-framework/
真的最好用

已經直接是template了



http://spin.atomicobject.com/2011/12/13/building-a-universal-framework-for-ios/
其實也可以
不過他似乎還不包含 resources  ...



下一個目標是把  core data放進去

=========



http://db-in.com/blog/2011/05/creating-universal-framework-to-iphone-ios/

http://mark-kirby.co.uk/2012/how-to-install-static-frameworks-on-xcode-4/

http://spin.atomicobject.com/2011/12/13/building-a-universal-framework-for-ios/

http://code.google.com/p/ios-static-framework/

https://github.com/kwylez/StaticFramework-Sample-Project/downloads

圖文版




http://simplyitinc.blogspot.tw/2011/04/creating-static-framework-in-xcode-4.html

還沒實驗過  先記錄一下!



For iOS there is no template in Xcode to build a framework for iOS.  In order to get around this, you can create a Cocoa Static Library project and modify it so that you can develop and compile a static iOS Framework.  Using the post at "http://www.cocoanetics.com/2010/05/making-your-own-iphone-frameworks-in-xcode/" as a basis for writing this tutorial I was able to get it working and used it in a another project by following the steps outlined in this post.  This is the first library I've ever tried to create outside of Java so please feel free to chime in with any comments or corrections.

Create the Xcode project for the framework(skip if you already have an existing project):
- Open Xcode and create a new project (File->New->Project)
- Under the "Framework & Library" section under iOS select "Cocoa Touch Static Library".
- Under "Product Name" enter the name you want to call your framework.
- Click "Next" and "Create".

Add a Bundle target:
- Click the "Add Target" button at the bottom of the Xcode window.
- Select the "Bundle" template under Mac OS X.
- Give it the name of your framework.
- Click "Finish".

Set the Build Settings:
- Change the following properties to the values indicated below...
- Base SDK (replace the value with the appropriate iOS SDK version for your framework).
- Build Active Architecture Only = No
- Architecture and Valid Architectures = $(ARCHS_STANDARD_32_BIT)
- Mac OS X Deployment Target = Compiler Default
- Targeted Device Family (choose the appropriate iOS device i.e. iPhone/iPad)
- Dead Code Stripping = No
- Link With Standard Libraries = No
- Mach-O Type = Relocatable Object File
- Wrapper Extension = framework
- Generate Debug Symbols = No

Modify Info.plist file:
- Under your frameworks "Supporting Files" folder should be a file named <framework>-Info.plist.  Modify the "Bundle OS Type code to "FMWK"

Modify the Prefix.pch file:
- The generated Prefix.pch file under "Supporting Files" contains a reference to the Cocoa framework header file.  Remove that reference from the file.

Remove unnecessary frameworks from your project:
- Under the "Frameworks" folder delete frameworks such as Cocoa.framework and AppKit.framework that your project does not rely on.

Add frameworks required by your framework:
- If the project was created from a Cocoa template, the Cocoa framework is setup by default and not UIKIt which is required for iOS projects.
- Drag and drop any required frameworks such as UIKit under the "Frameworks" folder in your project pane.  In the dialog box that comes up uncheck "Copy items into destination group's folder (if needed)".
- UIKit should be in a folder similar to the following - /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/System/Library/Frameworks/UIKit.framework

Add and develop your framework code files.

Add a new build phase for "Copy Headers":
- Select your framework target.
- Click the "Build Phases" tab.
- Click the "Add Build Phase" button and select "Add Copy Headers" from the pull-down menu.
- Under "Compile Sources" your source files should already be there, if not add them.
- Under "Link Binary With Libraries" remove any frameworks that might be present.
- Under "Copy Headers" add your .h  files to the section with the appropriate scope.  They can be "Public", "Private", or "Project".  You can drag them from the "Project" section to the "Public" or "Private" sections or from the project file pane.

Create Target for Universal Framework
-------------------------------------------------
- Create an "Aggregate" target named "<Framework Name> Universal Framework".
- Update the "Build Settings" by changing "SDKROOT" to "iphoneos".
- Click "Add Build Phase" and then "Add Run Script".  Copy the script below into the script area in "Run Script".  Be sure to update the "FMK_NAME" property to the name of your framework.

# Sets the target folders and the final framework product.
FMK_NAME=MyFramework
FMK_VERSION=A

# Install dir will be the final output to the framework.
# The following line create it in the root folder of the current project.
INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework

# Working dir will be deleted after the framework creation.
WRK_DIR=build
DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework

# Building both architectures.
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator

# Cleaning the oldest.
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi

# Creates and renews the final product folder.
mkdir -p "${INSTALL_DIR}"
mkdir -p "${INSTALL_DIR}/Versions"
mkdir -p "${INSTALL_DIR}/Versions/${FMK_VERSION}"
mkdir -p "${INSTALL_DIR}/Versions/${FMK_VERSION}/Resources"
mkdir -p "${INSTALL_DIR}/Versions/${FMK_VERSION}/Headers"

# Creates the internal links.
# It MUST uses relative path, otherwise will not work when the folder is copied/moved.
ln -s "${FMK_VERSION}" "${INSTALL_DIR}/Versions/Current"
ln -s "Versions/Current/Headers" "${INSTALL_DIR}/Headers"
ln -s "Versions/Current/Resources" "${INSTALL_DIR}/Resources"
ln -s "Versions/Current/${FMK_NAME}" "${INSTALL_DIR}/${FMK_NAME}"

# Copies the headers and resources files to the final product folder.
cp -R "${DEVICE_DIR}/Headers/" "${INSTALL_DIR}/Versions/${FMK_VERSION}/Headers/"
cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/Versions/${FMK_VERSION}/Resources/"

# Removes the binary and header from the resources folder.
rm -r "${INSTALL_DIR}/Versions/${FMK_VERSION}/Resources/Headers" "${INSTALL_DIR}/Versions/${FMK_VERSION}/Resources/${FMK_NAME}"

# Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.
lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/Versions/${FMK_VERSION}/${FMK_NAME}"

rm -r "${WRK_DIR}"

Run the "MyApp Universal Framework" target to build the framework.  The framework bundle should now be under the "Products" folder of your project.  To use it in another project simply drag and drop it from your framework project to a folder in your project.

Hope this was helpful!

中文 Xcode 3.x   http://www.cocoachina.com/newbie/env/2011/1009/3334.html