2012年11月30日 星期五

iOS IPA with sign on command Line

http://nachbaur.com/blog/building-ios-apps-for-over-the-air-adhoc-distribution

http://stackoverflow.com/questions/2664885/xcode-build-and-archive-from-command-line

還沒有研究  先記錄

iOS 各個Model 的型號

http://theiphonewiki.com/wiki/index.php?title=Models

各個 model的型號

2012年11月26日 星期一

2012年11月24日 星期六

iOS UIWebview


http://www.cocoachina.com/applenews/devnews/2012/1123/5167.html


有空再來看看哪些可以偷來用@@!

iOS 小技巧?!



http://www.cocoachina.com/applenews/devnews/2012/1123/5166.html


有些看起來還蠻有趣的!


1、Xcode调试技巧—在系统抛出异常处设置断点
有时候我们的程序不知道跑到哪个地方就 crash 了,而 crash 又很难重现。
保守的做法是在系统抛出异常之前设置断点,具体来说是在 objc_exception_throw处设置断点。
设置步骤为:首先在 XCode 按 CMD + 6,进入断点管理窗口;
然后点击右下方的 +,增加新的 Symbolic Breakpoint。
在 Symbol 一栏输入:objc_exception_throw,然后点击 done,完成。
这样在 Debug 模式下,如果程序即将抛出异常,就能在抛出异常处中断了。
比如在前面的代码中,我让 [firstObjctcrashTest]; 抛出异常。在 objc_exception_throw 处设置断点之后,程序就能在该代码处中断了,我们从而知道代码在什么地方出问题了。

2、计算UIlabel 随字体多行后的高度
+ (CGFloat)calcTextHeight:(int)textWidth text:(NSString *)text font:(int)fontSize {
    CGRect bounds, result;
    bounds = CGRectMake(0, 0, textWidth, 300);
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
    label.font = [UIFont systemFontOfSize:fontSize];
    label.text = text;
    result = [label textRectForBounds:bounds limitedToNumberOfLines:20];
    return result.size.height;
}

或者CGSize requiredSize = [introduceLabel.text sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(296.0f, FLT_MAX) lineBreakMode:UILineBreakModeTailTruncation];

3、计算当前label随字体增加的长度(单行)
CGSize boundingSize = CGSizeMake(320.0f, CGFLOAT_MAX);
CGSize requiredSize = [status.user.username sizeWithFont:[UIFont boldSystemFontOfSize:13] constrainedToSize:boundingSize lineBreakMode:UILineBreakModeWordWrap];
CGFloat requiredWidth = requiredSize.width;


4、view控件加边框
profileImageButton = [UIButton buttonWithType:UIButtonTypeCustom];
[profileImageButton.layer setMasksToBounds:YES];
[profileImageButton.layer setCornerRadius:4.0]; //设置矩形四个圆角半径
[profileImageButton.layer setBorderWidth:1.0];   //边框宽度
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGColorRef colorref = CGColorCreate(colorSpace,(CGFloat[]){225.0/255.0, 225.0/255.0, 225.0/255.0, 1.0 });
[profileImageButton.layer setBorderColor:colorref];//边框颜色

单独设置圆角
[iconImage.layer setCornerRadius:4.0];
[iconImage setClipsToBounds:YES];

5、时区返回格式为数字(-12—+12)  
-(NSString *)getTimeZone{
    NSString *zone = [[NSTimeZone systemTimeZone] description];//Europe/Berlin//       America/New_York//   Asia/Harbin
                                                                               //这三个可以用来测试exp:NSString *zone = [[NSTimeZone timeZoneWithName:@"America/New_York"] description];
    NSString *time = [[zone componentsSeparatedByString:@"offset "] objectAtIndex:1];
    int inv = [time intValue];
    int result = inv / (60 * 60);
    if (result>0) {
        return [NSString stringWithFormat:@"+%d", result];
    }
    return [NSString stringWithFormat:@"%d", result];
}

6、判定输入框不为空格以及空
   NSString *_textField=[textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    if ([_textField length] == 0) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"评论内容不能为空!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alertView show];
        return NO;
    }


7、根据当前键盘的高度来设置UITextField的位置
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardDidShowNotification object:nil];
}

- (void)keyboardWillShow:(id)sender {
    CGRect keyboardFrame;
    [[[((NSNotification *)sender) userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardFrame];
    CGFloat keyboardHeight = CGRectGetHeight(keyboardFrame);
    [self.textImageView setFrame:CGRectMake(0, 416-keyboardHeight, 320, 45)];
}
8、设置label ,imageview,等点击时事件
    UITapGestureRecognizer *imageTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImage:)];
   // [imageView setUserInteractionEnabled:YES]; 如果不能点击,设置可编辑
    [imageView addGestureRecognizer:imageTap];

9、判断剩余字数(字母数字符号两个算一个汉字)
-(int)charNumber:(NSString *)strTemp
{
    int strLength =1;
    char *p =(char *) [strTemp cStringUsingEncoding:NSUnicodeStringEncoding];
    for (int i=0; i<[strTemp lengthOfBytesUsingEncoding:NSUnicodeStringEncoding]; i++)
    {
        if (*p) {
            p++;
            strLength++;
        }
        else{
            p++;
        }
    }
    return strLength/2;
}

10、UIWebView加载gif图片  ——这样可以解决gif图片不能下载到本地加载,使用SDWebImage down也出现界面不流畅,卡的问题
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, [homeTableCell getImageWidth:funnyPic], [homeTableCell getImageHeight:funnyPic])];
        webView.backgroundColor = [UIColor clearColor];
       // webView.scalesPageToFit = NO; 这一句我一直没搞清楚,有时对,有时不对的,注释了吧
        //禁止webView的滑动 这样写主要是因为5.0以前的系统不能直接获取到webView.scrollView
        [(UIScrollView *)[[webView subviews] objectAtIndex:0] setBounces:NO];
// 不让有白色的边,这个margin是必须的  
        NSString *html = [NSString stringWithFormat:@"<html><body style=\"margin: 0px;\"><img src=\"%@\"></body></html> ",funnyPic.imageUrl];
        [webView loadHTMLString:html baseURL:nil];
        [imageView addSubview:webView];

11、插入加载更多 tableview reloadData闪的问题
        if (requestArray && [requestArray count] > 0) {
            int cellCount = [requestArray count];//获取一共有几行
            NSMutableArray *indexArray = [[NSMutableArray alloc]initWithCapacity:10];
            int numCountNow = [self.tableView numberOfRowsInSection:0];
            for (; cellCount > 0; cellCount--) {
                NSIndexPath *path = [NSIndexPath indexPathForRow:numCountNow + cellCount - 1 inSection:0];
                [indexArray addObject:path];
            }
            [self.tableView insertRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationNone];
        }

12、Image 加载16进制的 图片(编译成freamwork的时候不能直接加载png图片,要转化)
首先,使用UltraEdit把图片转化为16进制
static const char _playerPause_icon [] = {
    0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52,
    0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x1B, 0x08, 0x06, 0x00, 0x00, 0x00, 0x9A, 0xF6, 0x64,
    0x9C, 0x00, 0x00, 0x00, 0x39, 0x49, 0x44, 0x41, 0x54, 0x38, 0x8D, 0x63, 0x64, 0x60, 0x60, 0x38,
    0xC3, 0x80, 0x1D, 0x98, 0x60, 0x11, 0xC3, 0xAA, 0x96, 0xF1, 0xFF, 0xFF, 0xFF, 0xFF, 0xB1, 0x4A,
    0x30, 0x32, 0x32, 0xA2, 0x8B, 0xE1, 0x52, 0xCB, 0x84, 0xC3, 0x15, 0x24, 0x81, 0x51, 0x43, 0x46,
    0x0D, 0x19, 0x35, 0x64, 0xD4, 0x90, 0x51, 0x43, 0x46, 0x0D, 0xA1, 0xA7, 0x21, 0x00, 0xDD, 0x84,
    0x09, 0xFD, 0x6B, 0x3C, 0x1F, 0xCB, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42,
    0x60, 0x82
};
然后加载
[playButton setImage:[UIImage imageWithData:[NSData dataWithBytes:_playerPause_icon length:sizeof(_playerPause_icon)/sizeof(char)]] forState:UIControlStateNormal];

13、倒计时(剩余时间)
- (void)timerFireMethod:(NSTimer*)theTimer{
    
    id obj = [theTimer userInfo];
    NSDateFormatter *f1 = [[NSDateFormatter alloc] init];
    [f1 setDateFormat:@"yyyy-MM-dd HH:mm:ss.S"];
    
    NSDate *theDay = [f1 dateFromString:(NSString*)obj];
    [f1 release];

    NSCalendar *cal = [NSCalendar currentCalendar];//定义一个NSCalendar对象
    
    NSDate *today = [NSDate date];//得到当前时间
    
    //用来得到具体的时差
    unsigned int unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
    NSDateComponents *d = [cal components:unitFlags fromDate:today toDate:theDay options:0];
    
    NSString *countdown = [NSString stringWithFormat:@"%d日%d时%d分%d秒", [d month],[d day], [d hour], [d minute], [d second]];
    
    self.timeLabel.text = countdown;
    return ;
    
}

14、九宫格或者其他类型的坐标设置
        frame.size.width = 60;//设置按钮坐标及大小
        frame.size.height = 60;
        frame.origin.x = (i%3)*(60 + 32)+40;
        frame.origin.y = floor(i/3)*(60 + 24)+60;

2012年11月22日 星期四

git branch

http://blog.wu-boy.com/2011/03/git-%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6-branch-model-%E5%88%86%E6%94%AF%E6%A8%A1%E7%B5%84%E5%9F%BA%E6%9C%AC%E4%BB%8B%E7%B4%B9/


http://gogojimmy.net/2012/01/21/how-to-use-git-2-basic-usage-and-worflow/

嘗試利用  branch .....


現在簡單應用下面的指令


直接由 develop 開出分支 myfeature,並且直接切換過去
git checkout -b myfeature develop
# 直接下 git branch 觀看目前位置
  develop
  master
* myfeature
經過編輯修改並且 commit
git add test.php
git commit -a -m "Add: test.php"
合併分支:
先切換到 develop
$ git checkout develop
Switched to branch 'develop'
利用 –no-ff 合併分支(稍後說明為什麼使用 –no-ff)
$ git merge --no-ff myfeature
Merge made by recursive.
 test.php |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
 create mode 100644 test.php



2012年11月21日 星期三

Jenkins + Unit Test



掙扎了一陣子

後來決定用  GHUnit + OCMock + OCHAMCREST

(下午遇到的問題是....可能要先在自己的mac上 make過 framework才能跑 我猜是 SDK的問題)

接著可能要解決的問題

1. ghunit 的 templete file

2.  INSTALL OCMock + OCHAMCREST

3.  run on the Jenkins

4.  以及最重要的..... 究竟要怎樣使用qq


他有遇到的我也有遇到耶!
http://www.egeek.me/2012/10/03/jenkins-ghunit-launch-msg-error/



Jenkins + GHUnit

http://www.tuicool.com/articles/uUbuUn

http://gabriel.github.com/gh-unit/docs/appledoc_include/guide_command_line.html

http://gabriel.github.com/gh-unit/docs/appledoc_include/guide_ci.html


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



一直卡在最後出 report 的地方

後來想說還是用官方的  OCUnit

感覺整合性還是好很多

再配合  OCUnit2JUnit

應該會不錯用


繼續努力....orz


http://www.raingrove.com/2012/03/28/running-ocunit-and-specta-tests-from-command-line.html

要先多建立一個 scheme

然後設定其關連性

script 用  https://gist.github.com/2410839

用 系統內的好像會一直出問題  (系統內好像是新的 anyway  至少舊的可以用....)


最後再 jenkins 上面的指令用:
xcodebuild -workspace xxxxx.xcworkspace -scheme xxxxx -sdk iphonesimulator5.1 -configuration Debug TEST_AFTER_BUILD=YES clean build


iphonesimulator5.1   不用 iphonesimulator   這樣預設好像是會用  6.0  好像會有 顯示視窗大小的問題....



finally .....  我一直放錯重點  明明應該是要好好寫 Unit test  ,  卻一直放在產生 report 上

搞了一個下午+晚上+隔天早上  ....  終於弄出一個至少可以用的orz

時間真不夠用...QQ



other ref

http://www.gerardcondon.com/blog/2012/09/20/further-jenkins-setup-code-signing/

http://www.stewgleadow.com/blog/2012/02/09/running-ocunit-and-kiwi-tests-on-the-command-line/

http://hataewon.tumblr.com/post/30045666799/how-to-use-subprojects-with-xcode-and-jenkins

http://hataewon.tumblr.com/post/30327012898/continuous-integration-for-cocoa-using-jenkins-part-ii



Unit test  example ?!?!

https://github.com/iamleeg/BrowseOverflow/tree/master/BrowseOverflowTests