iOS 老项目问题处理集

1. Xcode 10 的坑:That command depends on command in Target 'x'x': script phase “[CP] Copy Pods Resources”

收到公司之前的项目,在最新XCode中编译出现一个Bug,提示如下:

Multiple commands produce '/xxx.app':
1) Target 'xxx' has create directory command with output '/Users/xxx/Library/Developer/Xcode/DerivedData/xxx-cbvukcttkoparwddqctpdtspmcov/Build/Products/Debug-iphonesimulator/xxx.app'
2) That command depends on command in Target 'xxx': script phase “[CP] Copy Pods Resources”

【 问题分析 】

​ 出现该问题是因为自Xcode10之后默认使用的build system是New build system,我们只要将build system设置成legacy build system就好了。

【 解决方法 】

​ 1.如图

image-20200730141039458.png

​ 2.如图

image-20200730141131039.png

2. 升级Xcode10、Xcode11, 报错 library not found for -libstdc++.6.0.9

【错误提示】

2067115-ee7de318d4cb4738.png

【错误原因】

​ 升级到XCode10后,由于去掉陈旧的libstdc++库替换为libc++,-libstdc++.6.0.9就被删除了

【解决办法】

######  方案1 Xcode9中拷贝 `-lstdc++.6.0.9`以及`libstdc++`等库到Xcode10中(真机和模拟器都需要拷贝)

​ 终端输入命令,打开Xcode的*lib库目录*,将需要的库文件从Xcode9目录下拷贝到Xcode10目录下:

​ 打开命令如下(Xcode9 - 复制):
​ 1)设备(真机):

open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib

​ 2)模拟器:

open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib

​ 打开命令如下(Xcode10/11 - 粘贴):

​ 1)设备(真机)

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/

​ 2)模拟器:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/

下载副本地址:GitHub - wangqi1221/lstdc-.6.0.9

如果还是报错,退出Xcode重新进入,编译一下就好了。

【意外问题】

替换完成后在模拟器iOS10.0以上运行会出现一个错误,如下:

Reason: no suitable image found.  Did find:
    /usr/lib/libstdc++.6.dylib: mach-o, but not built for iOS simulator

【解决办法】这里还需要拷贝旧Xcode中的

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libstdc++.6.0.9.dylib

并改名为libstdc++.6.dylib后粘贴到新Xcode同样的位置。
(注意在/Profiles/Runtimes/iOS.simruntime这里时需要右键显示包内容)。

附:

Xcode 11 里面需要对换一下路径
/iPhoneOS.platform/Developer/Library/CoreSimulator 中间的Developer和Library对换一下 重新弄一下

方案2、 替换苹果支持的libc++

​ 替换工程用到libstdc++.6.0.9以及libstdc++的地方,同时替换需要依赖该库的第三方如:第三方分享Mob:SMSSDK:http://wiki.mob.com/快速集成-11/文档中则对libstdc++的依赖进行了处理

libc2.jpg

3.iOS开发 -- iOS 14下popToRootViewControllerAnimated:YES 导致TabBar隐藏的问题

文章中的问题会出现在Xcode 12 + iOS 14上, 经过测试,

  • Xcode 11 + iOS14,

  • Xcode 12 + <= iOS 13

    (不会出此类问题.)

问题:

我们处理UITabbar在push的时候的显示和隐藏, 之前因该是如下的操作:

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
    } else {
        viewController.hidesBottomBarWhenPushed = NO;
    }
    [super pushViewController:viewController animated:animated];
}

这个在iOS 14之前是没问题的, 但是升级到iOS 14, 发现我们在执行 popToRootViewControllerAnimated:YES的时候, UITabBar隐藏了.

解决:

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.viewControllers.count > 0) {
        // 当前导航栏, 只有第一个viewController push的时候设置隐藏
        if (self.viewControllers.count == 1) {
            viewController.hidesBottomBarWhenPushed = YES;
        }
    } else {
        viewController.hidesBottomBarWhenPushed = NO;
    }
    [super pushViewController:viewController animated:animated];
}

你可能感兴趣的:(iOS 老项目问题处理集)