iOS之FAQ(都是我遇到过的)

做开发就会遇到各种各样的问题,以前都是看看解决了就过了,有时候遇到同样的问题,却忘了怎么解决,还要重新上网去找,干脆就留下点痕迹吧。。。

cannot create __weak reference in file using manual reference counting

解决1:

设置项目中的build setting -> Apple LLVM7.1 - Language - Objective C -> Weak References in Manual Retain Release YES

解决2:

用__unsafe_unretained 代替__weak,但是如果用__unsafe_unretained请注意下面的问题。
__unsafe_unretained specifies a reference that does not keep the referenced object alive and is not set to nil when there are no strong references to the object. If the object it references is deallocated, the pointer is left dangling.


You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. for architecture arm64

这是一个很早以前遇到的问题了,解决方法很简单,
设置项目中的build setting -> All - Combined - 搜索bitcode -> 置为No参考文章


昨天有朋友问我怎么保持蓝牙长连接,就是在后台也不断开,其实这问题百度上一搜一大把啊,谷歌我就不说了。

也说下解决方法吧,只要在info.plist中加入新建一行 Required background modes , 加入下面两项。App shares data using CoreBluetoothApp communicates using CoreBluetooth


duplicate symbols for architecture arm64

错误原因可能是:1.有重名的文件。2.import的时候把.h写成.m。
解决方法:前者搜索该文件名,改名或删除均可。后者改成.h即可。


Implicit declaration of function 'SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO' is invalid in C99

错误原因是这样的,我自定义了宏#define SYSTEM_RUNS_IOS7_OR_LATER SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")
解决方法也比较让我惊奇,只要在宏定义的地方添加如下代码即可

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

参考:http://stackoverflow.com/questions/23818606/semantic-issue-implicit-declaration-of-function


Application windows are expected to have a root view controller at the end of application launch

这个报错现在几乎是看不到了,我是下载了httpserver的demo,运行出错。问题就出在rootViewController上。
解决方法,只要设置rootViewController就行了。我将[window addSubview:viewController.view];改成window.rootViewController = viewController;运行ok...


fatal error: could not build module 'Foundation'

今天运行程序的时候突然冒出27个错,而且一看是系统的库,上网查了资料才知道是因为导入了.c的文件而造成的。
解决方法:在.pch文件中加上#ifdef OBJC 和#endif即可。


fatal error: No code signing identities found: No valid signing identities (i.e. certificate and private key pair) matching the team ID “********” were found.

这是我在Archive时遇到的,一看就知道是证书问题,参考了stackoverflow解决了。解决方法:点左上Xcode > 选择Preferences,在Accounts中找到你的Apple ID,然后点击View Details,等待加载,时间会有个1、2分钟的样子,在Provisioning Profiles栏中,download证书,然后问题解决。


fatal error:Missing iOS Distribution signing identity

还是打包上传的时候遇到的,依旧是证书问题,就不说原因了,直接说解决方法:
1.https://developer.apple.com/certificationauthority/AppleWWDRCA.cer下载最新的证书,双击安装
2.到钥匙串中将过期的证书删除即可。(别问我钥匙串在哪,也别说找不到过期的证书v)
3.没有第三了,问题已经解决了。


UIWebView手势无效问题

这几天用UIWebView添加上滑下滑手势,发现没有效果,查了资料才发现,UIWebView已经自带手势了,解决问题的方法很简单,添加一个方法:- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer方法实现起来也很简单,我看有的人直接return YES;,但我发现这样并不严谨,应该加个判断,如果是你添加的手势,return YES;否则return NO;
跑一下,OK〜


Undefined symbols for architecture x86_64:

缺少库,缺什么自己补什么就好了。。。


attempt to insert nil object from objects[1]'

插入数组或字典中得值为空,可先进行判断在插入


specifies a non-existent file for the cfbundleexecutable key

這是打包上傳時遇到的,原因是我添加了QQ的分享,只要在info.plist文件中刪除executable file 这个key即可


Failed to chmod user/Library/Developer/CoreSimulator/Devices NO Such File Or directory

這個出現的具體原因我也不是很清楚,在so上也能找到,我重置了一下模擬器就好了( Simulator -> Reset Content and Settings...),當然也有人說重置了沒用。。。,so鏈接:http://stackoverflow.com/questions/40485155/failed-to-chmod-user-library-developer-coresimulator-devices-no-such-file-or-dir


Failed to chmod user/Library/Developer/CoreSimulator/Devices NO Such File Or directory

這個出現的具體原因我也不是很清楚,在so上也能找到,我重置了一下模擬器就好了( Simulator -> Reset Content and Settings...),當然也有人說重置了沒用。。。,so鏈接:http://stackoverflow.com/questions/40485155/failed-to-chmod-user-library-developer-coresimulator-devices-no-such-file-or-dir


This action could not be completed.Try again.(-22421)

錯誤是在上傳項目時出現的,就是說你網絡有問題,繼續重試即可。


PCH was compiled with module cache path

出现这个问题应该是我复制项目所以报错,说路径不同了,只要把but后面的路径里的文件删掉,然后clean项目就好了


This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.

出现这个问题是我在iOS 10的手机上调用系统相机,然后就崩溃了

解决方法:
  1. 在项目中找到info.plist文件,右键点击以 Source Code形式打开
  2. 添加以下键值对,这里以 PhotoLibrary 作为例子
    NSCameraUsageDescription
    此 App 需要您的同意才能读取媒体资料库
  3. 注意,key 是绝对不能写错的,而 value 也就是你可以随意写

member access within misaligned address 0x000000000031 for type 'struct ListNode', which requires 8 byte alignment

这是一个c里面的错误,出现的环境是我做一个链表,alloc以后,调用此列表中的属性,然后报错,解决方法也很简单,alloc以后,对链表的每个属性赋值即可(没值就赋NULL)


All interface orientations must be supported unless the app requires full screen.

这只是一个警告,但是看着不爽,能解决就解决掉吧。这个警告是说App默认是有开启了多任务功能,而多任务功能是需要App支持所有方向,如果我们App是有需要支持多任务,则需要开启App对各个方向(上、下、左、右)的支持;如果App不需要开启多任务,则只需要将Target中Status Bar Style中的的 Requires full screen 勾选上就ok


Unable to find a specification for xxxxx.

这是在cocopods上安装库的时候遇到的问题,解决方法可以更新库pod repo update当然,也可以把库删了pod repo remove master,然后重装pod setup


Safe Area Layout Guide before iOS 9.0

出现这个问题是因为iOS11以后出现了Safe Area这个概念,在sb和xib中默认设置了Safe Area,解决方法有两个:
方法一:把系统版本提高到9.0或以上;
方法二:如下图所示取消Use Safe Area Layout Guides选项即可。


iOS之FAQ(都是我遇到过的)_第1张图片
123.png

[framework] CUIThemeStore: No theme registered with id=0

这是在控制台打印出来的,虽然没啥影响,但看着不爽,解决方法很简单,在 Assets.xcassets 文件夹中添加一张图片就行了。。。


tabBarItem的位置会从一个偏移位置闪现到正常位置

不影响使用,但看着很不爽,解决很简单,在didFinishLaunchingWithOptions方法中加一句[[UITabBar appearance] setTranslucent:NO];即可。。。


libMobileGestalt MobileGestalt.c:890: MGIsDeviceOneOfType is not supported on this platform.

编辑Scheme-> Run - > Arguments,在Environment Variables里边添加OS_ACTIVITY_MODE =禁用来屏蔽这些打印即可。


不断更新,未完待续。。。

版权声明:本文为 Crazy Steven 原创出品,欢迎转载,转载时请注明出处!

你可能感兴趣的:(iOS之FAQ(都是我遇到过的))