最近工作中遇到的问题以及解决方法总结

一、podfile文件格式错误
在跑一个很久没有更新的本地仓库的时候,pod install 报错。检查对比发现 podfile 格式太陈旧,最新版的 cocoapods 不在支持这种格式。
改为:

source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!

target 'xxxxxx' do
    pod 'BHRouter', :path => '../'
    pod 'BHFeature', :git => 'git@git.boohee.cn:ios/xxxxxx.git', :branch => 'master'
    target 'xxxxxxTests' do
        inherit! :search_paths

    end
end

二、项目编译报错 linker command failed with exit code 1 (use -v to see invocation)

对着这个错误,很常见,但引起这个错误的原因却是千奇百怪。这种错误很隐蔽,因为没有详细的错误信息提示。网上也有很多解决方案。但由于原因不一样,所以都无解。

后来发现在执行 pod install 的时候,有一个警告:

[!] Automatically assigning platform ios with version 7.1 on target BHRouter 
because no platform was specified. 
Please specify a platform for this target in your Podfile. 
See 'https://guides.cocoapods.org/syntax/podfile.html#platform'.

一般警告都是忽略掉了,所以没注意到,原来该项目引用的仓库的 podspec 指定的 platform 版本是 7.0。Xcode 就会自动把项目的 Target 设置为 7.0 ,而我的 Xcode 版本是 8.3.2 , 8.0 以上的 Xcode 版本是支持的系统是8.0以上的系统。才会有这种错误。

解决办法有两种:

第一,直接修改该项目的 iOS Deployment Target 为 8.0 。简单直接。

第二,修改所依赖的库的 podspec 中的指定版本,然后重新执行 pod install

如果项目所依赖的是自己的本地仓库,两种方法都可以。但对于开源的第三方,只能用第一种方法了。

三、监听网络状态的无效

需求是监听网络的变化,在 App 里给出友好的提示或者引导信息。
最初的代码如下:

  [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(reachabilityChanged:)
                                                 name: kReachabilityChangedNotification
                                               object: nil];
   Reachability *reachability = [Reachability reachabilityForInternetConnection];
    [reachability startNotifier];

可以经过几次试验,网络状态切换时, reachabilityChanged 方法大多数情况无法被调用。Google 了一下,最终看到有人提出,上面代码的 reachability 可能会被释放掉,所以检测无效。

于是把 reachability 声明为该类的全局属性:

@property (nonatomic, strong) Reachability *reachability;

把上面的代码块里的 reachability 改为 self.reachability 即可正常工作。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值