iOS编译填坑记录

25 篇文章 0 订阅
8 篇文章 1 订阅

以下是本人在iOS开发工作中使用的一些小技巧,记录一下。

 问题一这里有两个前提: 1、 工程中已经链接生成.a文件,同时target dependency也指定了  2、外加一个指定link里面也指定了链接库

为什么还会错误呢

问题二:

xcode编译过程中的环境变量

问题三


系统库找不到原来是C++库要用mm后缀,我了去

问题四

protobuffer里面默认采用的是C99的版本,导致编译出来是_t _n ,其他引用protobuffer的工程需要手动define,恶心啊

问题五

两次link framework会导致编译不过,报符号重复错误


问题6   Error: Argument list too long: recursive header expansion failed at /Applications/iWork '09/Pages.app/…/Contents/Resources

This is an Xcode "problem", as the error is generated from having a recursive search in your header search path. I've solved this in the past by unchecking the "Recursive" flag on items in the Header search path and instead link to each directory directly. There might be other (better) ways to solve this problem but it appears to be somewhat a bug with Xcode not reporting the error correctly when it is hit with a path it can not fully resolve.

There is also some info here about this error:

Xcode 3.1 problem checking dependencies | Cocoabuilder

There someone wrote, 

Since GCC doesn't natively support recursive search paths, Xcode simulates them by expanding such a path into a discrete -I or -F or -L flag for each directory under the parent directory, but this can rapidly expand to the point that it results in a command line too long to be issued.

The difference between Xcode 3.0 and 3.1 here is that Xcode 3.0 would silently stop expanding the recursive search path if it got too long and simply use whatever it had computed up to that point, which would result in semi-deterministic (and extremely difficult to diagnose) errors for certain types of projects. So now Xcode emits an error if it was unable to fully expand the recursive search path.

So you may need to remove that recursive search path, or modify it to expand to a smaller set of directories, or convert it to a smaller set of non-recursive search paths. Or, alternately, reorganize your source to have fewer directories the path can expand to.

Incidentally, having a smaller set of expansions could also lead to somewhat-faster compilation times, since it's fewer directories that the compiler has to search in when compiling each file. (I don't know the magnitude of impact this would have, though.)


问题7   touch framework卡死

关闭所有程序重新编译无效, 关闭xcode编译无效,只有重启电脑才有效!!!!

问题8  

While editing in the storyboard, specifically assigning a view controller to a specific class, I suddenly encountered this error when I wanted to run the project.

Main.storyboard: Internal error. Please file a bug at bugreport.apple.com and attach "/var/folders/79/_jh611t15qsfcx165_jv_20h0000gn/T/IB-agent-diagnostics_2015-10-28_00-33-12_730000".

And now I can't run my project anymore. I couldn't find any information regarding to this anywhere else. Did anyone encounter this before?

enter image description here

解决方案:   I faced the same issue. And it was solved by cleaning up the build files.

cmd + shift + k

AND

cmd + option + shift + k

Hope this helps Thanks.

问题9:  debug、build、attach ios直接卡死


重启ios手机,注意是重启手机哦,不是重启xcode,不是重启mac,是重启手机,够坑

问题10: The maximum number of apps for free development profiles has been reached.

删除手机上多余的app,就搞定

问题11


问题12  如果使用了forceload就要link depends加上依赖关系,没有foceload,也要加上depend依赖关系,主工程对所有的静态库都要加上依赖关系; 工程的目录关系直接影响着依赖关系的消失,删除工程中的树形结构关系,就等于潜规则删除了依赖关系



1.使用XXX.pch文件便捷开发+加速Build

在IOS开发的项目中有一个XX_Prefix.pch

XX_Prefix.pch:扩展名.pch表示"precompiled header",这是一个你工程要用到的来自于外部框架的头文件列表。xcode将编译这些头到文件,这将减少你在选择Build 或Build and Go时编译项目的时间。通常用到的头文件已经自动包含了pch,系统编译每个.m文件前,都会先imort这个文件。这样就节省了添加include的时 间,相当于加速编译

还有就是可以再这里面放入宏,在整个工程中都可以用.

添加方法:

  

在targets->Build Setting中Apple LLVM 7.0 - language中做如下修改

例如在一个项目中有一个hello.h文件,需要在所有.m文件中都要包含这个文件就可以在

XX_Prefix.pch文件中引入hello.h

2.在一个应用中打开其他应用.

在iOS开发中,如何实现从app1打开app2。

    基本的思路就是,可以为app2定义一个URL,在app1中通过打开这个URL来打开app2,在此过程中,可以传送一些参数。下面来讨论一下具体的实现过程。

1. 在app2的info.plist中定义URL,就是在文件中添加URL types一项。可按下图进行添加。

2. 在app1的代码中打开刚才定义的URL,代码如下:

1  NSURL *url = [NSURL URLWithString:@"myapp://test?para1=1¶2=2"];  
2 [[UIApplication sharedApplication] openURL:url]; 

当然,这个URL的形式可以是其他形式的,只要以"myapp://"开始即可。

    这样,就可以在app1中打开app2.

    打开之后,会调用app2的AppDelegate的

 

1
- ( BOOL )application:(UIApplication *)application openURL:( NSURL  *)url sourceApplication:( NSString  *)sourceApplication annotation:( id )annotation

 

 由于URL是自己定义的,所以会存在URL重复的情况。经过测试发现,如果试图打开这个URL,那么会打开先安装的那个应用.

 3.在Xcode中使项目的Build随项目的启动而递增.

在下图所示位置加入

1
2
3
4
version=`/usr/libexec/PlistBuddy -c  "Print CFBundleVersion"  $PRODUCT_SETTINGS_PATH`
version=`expr $version + 1`
/usr/libexec/PlistBuddy -c  "Set :CFBundleVersion $version"  $PRODUCT_SETTINGS_PATH
#/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $version" $PRODUCT_SETTINGS_PATH 这行代码会让version也自增,一般不需要

 

4.界面跳转.如电商项目中,A:商品界面(不是rootViewController)B:付款界面C:订单界面,想直接从C跳到A(中间跳转没有出现B的过渡效果),这时使用popToViewController时不行,popViewControllerAnimated也不行的情况下.可以使用:

 

1
[ self .navigationController popToViewController:[ self .navigationController.viewControllers objectAtIndex:1] animated: YES ];

 或者

1
2
3
4
5
for  (UIViewController *controller inself.navigationController.viewControllers) {
     if  ([controller isKindOfClass:[你要跳转到的Controller  class ]]) {
         [ self .navigationControllerpopToViewController:controller animated: YES ];
     }

 5.如何判断一个页面是web页面还是iOS原生页面.

长按界面,如果出现可复制的界面就是web界面.

 6.在Xcode里如何保证不会因为手残改动了系统的源生源码文件(降低权限).

终端输入:

cd /Applications/Xcode.app/
sudo chown -hR root:wheel Contents

7.使用Cocoapods导入的第三库文件,发现import无法提示.

9.cocoapods升级或者降级:

升级:

1
2
3
4
5
sudo gem update --system   //更新gem
sudo gem install cocoapods  
pod setup
 
pod --version   //查看版本

最近把mac系统升级到10.11系统,但是在用pod install命令的时候,却提示command not found或者:

在stackoverflow搜到的解释是这样的,This is happening because Apple has enabled rootless on the new install,也就是说在10.11系统上苹果已经启用无根的安装.

所以,保证Cocoapods在OS X 10.11系统上的正常使用,我们需要在命令行输入这样一句话:

1
sudo gem install -n /usr/local/bin cocoapods

  

降级:

1
sudo gem uninstall cocoapods   //选择哪个版本,之后Y
1
<code>sudo gem install cocoapods -v 0.34.4</code>    //选择那个版本

其中的Podfile文件最好是用Xcode编写,省的报错. 

10.Xcode在archive时出现no identity found:

1.首先确定开发者账号的相应证书和描述文件是否是最新,打开钥匙链删除旧版,更新新版

2.Xcode->prefrence->Accounts.重新添加appid,把多余的描述文件删除,重新下载新的描述文件.

3.整改项目里面的code Signing identify和PP文件.

4.clean一下.

 11.因为Cocoapods导致有些工程会出现liarary not funnd for -lPods如图所示:

同时,在相应位置处,其他导入的库正常,只有这个报红现象,右键show in finder也没反应.哪怕重新添加或者重新是用Cocoapods再次导入也无济于事.

依然报红,可以archive打包成ipa,但是无法连接手机测试观察,按照网上给的很多方法依然无效.只能:

新建一个全新项目,把原来的库重新导入新工程一次,一般新工程里面的libPod.a就是正常的了,如果非正常就是Cocoapods的原因了.如果正常就把新工程的libPod.a文件手动拷入原来的工程之中.

原工程仍然报红,但是可以连接手机测试了.

12.用xml格式打开xxx.plist.

13.点击按钮直接跳转至APP store相应APP的下载页面.

以微信为例,想要点击按钮跳转到APP store的微信下载页面.

最为关键的是跳转链接,这里的链接不是像https://appsto.re/cn/S8gTy.i这种.也不是

https://itunes.apple.com/cn/app/wei-xin/id414478124?mt=8(这种跳转中间会有Safari的过渡)

如果想要直接跳转至微信的下载页面,可以把https://换为itms:// 或者 itms-apps://.如:itms-apps://itunes.apple.com/cn/app/wei-xin/id414478124?mt=8

这种可以直接跳转至APP store的下载页面.其中链接可以使用Mac的APP store或者iTunes获取.

为了让开发者宣传自己产品时,下载地址更简短易记,苹果开放了 appstore.com “短” 链接服务。规则如下:

开发商主页

iOS:https://appstore.com/<公司名>,比如,http://appstore.com/smule
Mac:https://appstore.com/mac/<公司名>,比如,http://appstore.com/mac/popcap
应用下载地址
iOS:https://appstore.com/<应用名>,比如,http://appstore.com/ocarina
Mac:https://appstore.com/mac/<应用名>,比如,http://appstore.com/mac/peggle
开发商旗下 App
iOS:https://appstore.com/<公司名>/<应用名>,比如,http://appstore.com/smule/ocarina
Mac:https://appstore.com/mac/<公司名>/<应用名>,比如,http://appstore.com/mac/popcap/peggle
评论App跳转页面:itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=448165862
14.使用AFNetworing 3.0报错信息为:unacceptable content-type: text/html" 

对应到自己的项目里面,我用的是AFNetworking这套网络请求包,需要改的是:

AFURLResponseSerialization.m文件

226行:

self.acceptableContentTypes = [NSSetsetWithObjects:@"application/json", @"text/html",@"text/json",@"text/javascript", nil];

加上蓝色部分,其实就是添加一种服务器返回的数据格式。

15.因为Mac系统升级和Xcode升级导致Cocoapods失效.

1.如果只是Xcode升级导致Cocoapods失效只需在终端中:

(这里最好先打开Xcode)

a.先获取到UUID:

defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID

如:  XXXX-XXXX-VVVDF-JHFF

b.find ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins -name Info.plist -maxdepth 3 | xargs -I{} defaults write {} DVTPlugInCompatibilityUUIDs -array-add  这里加上上面的UUID

如:find ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins -name Info.plist -maxdepth 3 | xargs -I{} defaults write {} DVTPlugInCompatibilityUUIDs -array-add  XXXX-XXXX-VVVDF-JHFF

c.把Xcode完全退出,接着重启,会弹出是否加载插件界面,加载插件即可.

2.因为Mac系统升级导致Cocoapods失效:

这里的GEM_PATH会显示为空

解决方案1:

终端里输入:gem env

可以查到gem的安装路径,找到SHELL PATH,如:

接着依次试一下上面的这些路径.(这个方案我没用亲自试过,太麻烦)

解决方案2:

终端输入:sudo gem install -n /usr/local/bin cocoapods   

安装完成之后,接着在cocoapods插件的GEM_PATH里写入    /usr/local/bin    即可

(这个方案亲测可用)

 15.使用Xcode查看不同机型下的UI效果图.

1.首先打开storyboard或者xib,点击左上角的符号(如下图1中),接着Preview,然后按住option+shift键,选择你想要查看的视图文件.

 

2.接着会跳出下面的视图.双击+号

3.OK,接着右面会弹出各尺寸的效果图.点击+号可以添加机型

 16.查找私有api字段:

有时在上传APP Store时会报使用私有API的问题,解决方案:

cd  到项目文件夹

grep -r XXXX

上面就是查找私有字段XXXX所在的目录

 17.出现Unable to copy asset information from https://mesu.apple.com/assets/for asset type com.apple.MobileAsset.TextInput.SpellChecker 或者copy matching assets reply或者Daemon configuration query reply字样,如:

 

我的解决方案:在storyBoard中,修改TextView中的correction和spell Checking 为NO.如:

 

18.查看plist文件中key的正确原始值:

 

 

19.修改github上面的源码类型显示.如

1.打开命令行,cd 到本地仓库的项目根目录.然后新建一个文件 .gitattributes

1
touch  . gitattributes

2.用文本编辑器打开该文件,如果隐藏,需要先  打开隐藏文件显示(第10)

然后输入

1
2
*. h  linguist - language = swift
*. m  linguist - language = swift

  意思就是将.h 和.m文件当作Swift语言来统计,简单粗暴。

3.再次提交改变到github上即可.  

 

IOS重构中的那些坑


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值