i-chou's tech blog

Android iOS

Ios Sdk 8 Symbol _NSURLAuthenticationMethodServerTrust Not Found

| Comments

今天把做到收尾部分的新项目放到Xcode6上用iOS8SDK运行,出现ios sdk 8 Symbol _NSURLAuthenticationMethodServerTrust not found错误。

解决方法分享一下:

由于用到的AFNetworking是用官方推进安装方式CocoaPods方式安装的。那么遇到这个问题就可以在pods项目下的Targets Support FilesPods下面找到Pods.xcconfig文件,在里面找到OTHER_CFLAGS关键字里面的-framework Foundation,把-framework Foundation剪切到-framework CFNetwork的前面,保存,Clean and re-build/run

OK, 希望对你有用。

这个办法来自https://github.com/AFNetworking/AFNetworking/issues/2109

项目协作中Xcode Search Paths问题

| Comments

Xcode引用库的时候,编译器会自动添加一个库文件的绝对路径进去,这种情况下,如果其他人从repo上pull下来编译项目就容易出问题,因为找不到之前那个人引用路径下存放的文件了嘛。

那么,引用库或使用CocoaPods的时候,要注意手动把Build Settings里面的Framework Search Paths,Header Search Paths,Library Search Paths中的绝对路径都删掉,改成相对路径,最简单的办法时,全部删掉,然后加入一个../**即可。

顺便,最近Xcode5.1升级导致诸多在架构编译层面的问题。其中一个就是Xcode5.1默认是64位编译器编译。

手动关闭的方法是:选中Targets—>Build Settings—>Architectures。双击Architectures,选择other,删除$(ARCHS_STANDARD),然后增加armv7armv7s,clean一下再编译。 官方不推荐将Valid Architectures的内容修改,所以最好使用上面的方法关闭64位编译。

Those Pop Plug-ins for Xcode

| Comments

  • Alcatraz

    Alcatraz is an open-source package manager for Xcode 5. It lets you discover and install plugins, templates and color schemes without the need for manually cloning or copying files. It installs itself as a part of Xcode and it feels like home.

    (亲测Xcode5.1可用)

    项目地址: https://github.com/mneorr/Alcatraz img img

  • Lin

    Xcode5 plugin showing completion for NSLocalizedString and localizedStringForKey:value:table:

    (兼容到Xcode5,5.1不可用)

    项目地址: https://github.com/questbeat/Lin

    img

  • KFCocoaPodsPlugin

    XcodePlugin for CocoaPods with pod commands/console output, user notifications & code completion.

    (兼容到Xcode5,5.1不可用)

    项目地址: https://github.com/ricobeck/KFCocoaPodsPlugin

    img img

  • VVDocumenter-Xcode

    Xcode plug-in which helps you write Javadoc style documents easier.

    (亲测Xcode5.1可用)

    项目地址: https://github.com/onevcat/VVDocumenter-Xcode

    img

  • Fuzzy Autocomplete for Xcode

    This is a Xcode 5 plugin that patches the autocomplete filter to work the same way the Open Quickly works.

    It performs very well, and the fuzzy matching actually uses Xcode’s own IDEOpenQuicklyPattern.

    I wrote a blog post on how I used dtrace to figure out what to patch: Reverse engineering Xcode with dtrace

    Like nifty tools like this plugin? Check out Shortcat, an app that lets you control your Mac more effectively with your keyboard!

    (亲测Xcode5.1可用)

    项目地址: https://github.com/chendo/FuzzyAutocompletePlugin

    img

  • ColorSense-for-Xcode

    Plugin for Xcode to make working with colors more visual

    (兼容到Xcode4.5)

    项目地址: https://github.com/omz/ColorSense-for-Xcode

  • Unused

    A Mac app for checking Xcode projects for unused resources.

    这个虽然不是Xcode插件,但是确实是很有用的东西,他可以把项目中不用的资源文件在可视化窗口中检索出来,以辅助开发人员减少项目中浪费掉的空间。

    项目地址:https://github.com/jeffhodnett/Unused

Xcode5.1 Updated to Beta5

| Comments

Xcode5.1 Beta5iOS7.1Beta5出来有一周时间了,这次更新苹果把Xcode里的64编译变成了默认,而没有了选项,如果你的项目编译时出了问题,请检查一下编码是否支持64位。

下面有一篇介绍如何为64位编译应用的文章,分享出来,多少会了解一些为64位应用编译所需要的基本东西。 iOS 7: 如何为iPhone 5S编译64位应用。

如果您还没有充分准备好为64位编译您的应用,那么请在Xcode5.1项目的Target中Build Settings–>Architectures–>Valid Architectures中的arm64删掉,只保留armv7armv7s即可。但终究是要兼容64位的,所以,还是抓紧准备吧。

ios7.1 Beta版升级事件

| Comments

昨晚因为电话找不到了,就在MAC上iCloud里的Find My iPhone呼叫了一下,第二天早上一拿起手机发现让我填写AppleID和密码激活iPhone。我以为是因为昨天呼叫导致的。结果填写时候发现怎么验证都不通过,经查发现,Beta版不让激活。但是不对啊,之前还激活过,就以为是苹果新加的东东。

连上iTunes发现iPhone开着Find My iPhone是无法恢复备份的,但又无法进入系统关掉它。只好再一次进DFU模式刷机。刷成iOS7.0.4系统。可是,我之前的备份是7.1的Beta3的,不让我恢复,只能又固件刷到7.1的beta3(因为Beta4实在无法使用,不知道其他人的怎么样,反正在我的手机上极其不稳定,所以就不打算继续升级Beta版了),然后呢,还是激活不了。

上班以后同事同样出现了无法激活的情况,才发现,是Beta3的测试期限到了。。。20M的宽带下载个1G+的Beta5固件,吃奶的劲都使出来了,还是抓紧分享出来为他人提供方便吧。需要的朋友请自己去百度云下载。

iOS7.1 Beta5固件云盘地址: http://pan.baidu.com/s/11UoUE

iOS Define for Coding Faster

| Comments

以下是我在开发中常用的可以提高开发效率的宏

/* fast make */

#define ccp(__X__,__Y__)             CGPointMake(__X__,__Y__)

#define ccs(__W__,__H__)             CGSizeMake(__W__,__H__)

#define ccr(__X__,__Y__,__W__,__H__) CGRectMake(__X__,__Y__,__W__,__H__)


/* fast creation */

#define IMG(name)       [UIImage imageNamed:(name)]

#define IMG_VIEW(name)  [[UIImageView alloc] initWithImage:[UIImage imageNamed:(name)]]

#define LocalStr(key)   NSLocalizedString(key,key)

#define SFONT(size)     [UIFont systemFontOfSize:(size)]

#define FONT(s)         [UIFont fontWithName:@"Arial" size:(s)]

#define BFONT(size)     [UIFont boldSystemFontOfSize:(size)]

#define BUNDLE(name)    [[NSBundle mainBundle] pathForResource:(name)]

#define URL(url)        [NSURL URLWithString:url]


/* fast appending */

#define ADD(__x__, __y__) [__x__ stringByAppendingString:__y__]


/* iOS_Version */

#define IS_IOS7 ((floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1))


/* Components size */

#define SCREEN_WIDTH         [[UIScreen mainScreen] bounds].size.width

#define SCREEN_HEIGHT        [[UIScreen mainScreen] bounds].size.height

#define NAV_BAR_HEIGHT       44

#define NAV_BAR_HEIGHT_IOS7  64

#define TOOL_BAR_HEIGHT      44

#define TAB_BAR_HEIGHT       49

#define STATUS_BAR_HEIGHT    20


/* current language */

#define CN 1

#define ENG 2

#define JAN 3


/* color helper */

#define COLORRGBA(c,a) [UIColor colorWithRed:((c>>16)&0xFF)/255.0 \
                                   green:((c>>8)&0xFF)/255.0   \
                                    blue:(c&0xFF)/255.0        \
                                   alpha:a]

#define COLORRGB(c)    [UIColor colorWithRed:((c>>16)&0xFF)/255.0 \
                                   green:((c>>8)&0xFF)/255.0   \
                                    blue:(c&0xFF)/255.0        \
                                   alpha:1.0]


/* log helper */

#define LOG_STR(str)     NSLog(@"%@", str)

#define LOG_INT(int)     NSLog(@"%d", int)

#define LOG_FLOAT(float) NSLog(@"%f", float)

#define LOG_ERROR(exception,reason) NSLog(@"function:%s | line:%d | exception:%@ | reason:%@",__func__, __LINE__,exception,reason)

Unable to Process Application info.plist Validation at This Time Due to a General Error

| Comments

前几天美国圣诞放长假,往AppStore提交应用时提示28号以后才行。

今天提交前Validate时候遇到个问题,相信不止我一个人遇到,错误信息就是:

“Unable to process application info.plist validation at this time due to a general error.Please try again later.”

如果你确信你的签名认证文件没有弄错,那么恭喜你,这个错误并不是本地错误,而是苹果服务器方面的错误,只需耐心等待即可。如果只等待不能满足你好动的本性,你就再review一遍吧,也许在review这段时间会有新的发现。

Use Eclipse-Style ShortcutKey on Xcode

| Comments

相信有一些小伙伴即使用着高大上的Xcode,也还是习惯用Eclipse的一些更亲民的快捷键。 那么就将搜集到的定制Eclipse快捷键的方法分享在这里,缺点是每次Xcode升级,需要重新配置,不过有些插件可以统一管理Xcode的配置文件和插件,这里就不讲了。

首先找到Xcode中的自带的配置文件 /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/A/Resources/ IDETextKeyBindingSet.plist 这个文件里配置了一些可以设置快捷键的操作, 使用常用的编辑器打开它(需要root权限)。

然后把这段配置

<key>GDI Commands</key>
    <dict>
        <key>GDI Duplicate Current Line</key>
        <string>selectLine:, copy:, moveToEndOfLine:, insertNewline:, paste:, deleteBackward:</string>
        <key>GDI Delete Current Line</key>
        <string>moveToEndOfLine:, deleteToBeginningOfLine:, deleteBackward:, moveDown:, moveToEndOfLine:</string>
        <key>GDI Move Current Line Up</key>
        <string>selectLine:, cut:, moveUp:, moveToBeginningOfLine:, insertNewLine:, paste:, moveBackward:</string>
        <key>GDI Move Current Line Down</key>
        <string>selectLine:, cut:, moveDown:, moveToBeginningOfLine:, insertNewLine:, paste:, moveBackward:</string>
        <key>GDI Insert Line Above</key>
        <string>moveUp:, moveToEndOfLine:, insertNewline:</string>
        <key>GDI Insert Line Below</key>
        <string>moveToEndOfLine:, insertNewline:</string>
    </dict>

放到上面提到的IDETextKeyBindingSet.plist里,放在文件的最后的这两行之前:

    </dict>
</plist>

配置解读:

key是名称,对应的string是对应的一组操作。

  • GDI Duplicate Current Line 复制当前行到下面一行
  • GDI Delete Current Line 删除当前行
  • GDI Move Current Line Up 把当前行往上移动一行
  • GDI Move Current Line Down 把当前行往下移动一行
  • GDI Insert Line Above 在当前行上面增加一空行
  • GDI Insert Line Below 在当前行下面增加一空行(不管光标是否在行尾)

copy以后重启Xcode,在Xcode菜单中,打开Preferences,选中Key Binding,在右上方搜索GDI, 会出现类似下图的显示,如果没有的话,请检查上面的每步操作。

双击右边的空白处,就可以为每个功能设置不同的快捷键。

本文参考自:Xcode自定义Eclipse中常用的快捷键

UIKit in Release Notes for iOS 7.1 Beta2

| Comments

Known Issues

  • If a UITextField or a UILabel that is baseline aligned with constraints has attributes that change after the constraints have been added, the layout may be incorrect. The exception to this is -setFont: on UILabel, which should work as expected.

    Workaround: Avoid making changes in UITextField or UILabel after adding baseline-alignment constraints. If you must make changes, you should remove the constraints and then reapply them afterward. Note that this is a performance hit, so don’t do it unless it is necessary.

  • The backIndicatorTransitionMask from a storyboard or a xib will not be interpreted correctly at runtime.

    Workaround: Set the backIndicatorTransitionMask in code.

文本自定义行高以后高度自适应的解决方法

| Comments

本文要说的是,Frame高度根据文本内容自适应,而非UITextView的滚动显示哦~(当然不是滚动显示,那属性就是UITextView继承过来直接用的)

  • iOS7以前的最佳解决方案:

    自定义TextView继承UITextView并加入以下方法。1.5em可修改

      - (id)styleString {
          return [[super styleString] stringByAppendingString:@"; line-height: 1.5em"];
      }
    

    然后在通过下面方法给frame赋值

      CGRect frame = _textView.frame;
      frame.size.height = _textView.contentSize.height;
      _textView.frame = frame;
    

    需要注意的是contentSize只在UITextViewaddSubview以后才有效,所以要先把它加到画面上再,给它一个初始的frame,让它先得以计算出自己的contentSize

  • iOS7的最佳解决方案是:

    自定义TextView继承UITextView实现下面的init方法,给textView设定行高。

      - (id)initWithFrame:(CGRect)frame lineHeigth:(float)lineHeigth font:(UIFont *)font {
    
           self = [super initWithFrame:frame];
           if (self) {
                        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    
                        paragraphStyle.lineHeightMultiple = lineHeigth;
                        paragraphStyle.maximumLineHeight = lineHeigth;
                        paragraphStyle.minimumLineHeight = lineHeigth;
                        NSDictionary *ats = 
                                   @{NSFontAttributeName:font,NSParagraphStyleAttributeName : paragraphStyle};
    
                        self.attributedText = [[NSAttributedString alloc] initWithString:@“ “ attributes:ats];
                        self.lineHeight = lineHeigth;
                      }
            return self;
      }
    

    然后通过以下方法计算出textView的实际高度,继而确定frame的height。 因为之前有人说UITextView默认的上下左右padding均为8px,也就是下面16的由来。 所以在计算时要考虑进去才能保证文本显示完整。

      + (float) heightForTextView: (UITextView *)textView WithText: (NSString *) strText lineHeight:(float)height
      {
        float fPadding = 16.0;
        CGSize constraint = CGSizeMake(textView.contentSize.width - fPadding, CGFLOAT_MAX);
    
        CGSize size = [strText sizeWithFont:textView.font
                          constrainedToSize:constraint
                              lineBreakMode:UILineBreakModeWordWrap];
    
        float fHeight = size.height*height/textView.font.lineHeight + 16.0;
        return fHeight;
      }
    

    需要注意的是,本文讲的是自定义行高,所以,在下面方法里加上个lineHeight参与计算。

    其实从开发文档看,NSMutableParagraphStyle 在iOS6.0及以后都是有效的,但是我不知道为什么在iOS7上计算很精确,在iOS6上,结果却不令人满意。原因仍在调查中。

    不过,幸好有上面说的 <iOS7以前的最佳解决方案> ,要不然就要用<稍微差一点的解决方案>了,那么就顺带说一下<稍微差一点的解决方案>是什么吧^_^

  • 稍微差一点的解决

    使用开源控件 > TTTAttributedLabel

    这个控件之前由于性能问题一度被我遗弃过,后来版本更新以后,性能上来不少,但是仍然有些bug。我发现的bug就是当字体小于12号,或者当行数过多,并且lineHeightMultiple>1的时候,计算高度会存在偏差,行数越多偏差越大。

    那么也就是说,如果你一个文本不需要显示数百行,在此基础上对文本其他属性有追求,并且苦逼的要考虑兼容iOS7以下用户的话,可以使用 TTTAttributedLabel ,因为这个控件在伴随有 Text Kit 的iOS7出来之前还是还是相当牛逼的,而更牛逼的 Text Kit 让我们在文本显示领域看见了曙光!顺便奉劝一句,要是你的iOS7用户群达到95%以上,就果断抛弃那些抱着3年前的iPhone4而不敢升级系统的陈旧用户吧。