Xcode 错误、报错、警告集锦

1,153 阅读7分钟

以前遇到的各种Xcode报错!都放进来了!以后还有会继续加入!相当于一个记错本!

CoreData (使用“Class Definition”) Target '' (project '') has compile command with input ''

错误原因:实体属性Codegen(编译,生成)值为非Manual/None,创建出来的类编译后会报错。   解决方案:选中实体将实体属性Codegen(编译,生成)值改为Manual/None,清空当前build,重新编译

打包、上架
WARNING ITMS-90076: "Potential Loss of Keychain Access. The previous version of software
has an application-identifier value of ['G3WRS4SYLU.com.MMP.LiLiVaVa'] and the new 
version of software being submitted has an application-identifier of ['3FKGU7B68C.com.MMP.LiLiVaVa']. 
This will result in a loss of keychain access."

⚠️警告的原因:打包上架的应用最近从另一个帐号转让到了另一个帐号,这仅仅是个警告,并不影响上传及服务器编译。

错误
[ A ]. 本地化字符串文件不能使用。
  • 【1.】清理建文件夹,删除里面的一切DerivedData文件夹(位于“/Users/个人PC用户名/Library/Developer/Xcode/DerivedData”)路径下的缓存文件(占很大的内存空间),删除里面的程序,重新启动Xcode,重建工程。 DerivedData文件夹
  • 【2.】去项目目录里,手动地创建个“infoplist.strings”的文件,第一次在“en.lproj文件夹和第二次在“fr.lproj文件夹

[ B ]. Apple Mach-O Linker Error

Linker command failed with exit code 1 (use -v to see invocation)

例子🌰: 原因:重复引用多个文件或目录

导入时,错误地导入为“.m”文件:

[ C ]. installation failed,Invalid argument

应用程序编译通过,但是运行时,出现下面的提示框:“installation failed Invalid argument”

原因: “infor.plist文件中的Bundle indentifier置为空了!!

解决填写Bundle indentifier就行了!

报错
[ A ]. 未引入库文件( .m文件)

一般是引入相应的库文件(或“.m文件)。在引入三方库的时候都会提供“.a文件framework,里面装的是第三方库所提供的对“.h”文件的实现,只有加进去了才能找到“.h”文件里面方法实现 解决办法:检查工程里是否已经把对应文件加了进来。 (PROJECT -> TARGETS -> Build Settings -> Compile Sources -> 点“+”,添加“WeiboApi.m”文件) 若是已经加了,则在“build phases”底下的“compile sources”中入相应的“.m文件,或者在“link binary with libraries”中入相应的库文件

[ B ]. 一对象被释放多次:Thread 1: signal SIGABRT

往往是一个对象被释放了多次(多次释放)。大多是粗心所致。

有一种情况称为过渡释放,比较隐蔽

 NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
 self.myData = [userDefault objectForKey:@"myCollectData"];

这种写法是错误的!我们自己并没有将内存分配给myData。所以 编译器对这块内存有控制权,而不是我们自己! 所以,在某个时刻,我们不能保证myData是否有效。更不能保证程序到最后 进行了“[_myData release];”操作!

根据 “谁分配,谁管理” 的原则!我改写成了如下形式:

 NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
 NSData * my_data = [userDefault objectForKey:@"myCollectData"];
 self.myData = [NSData alloc] initWithData:my_data];

确保进行了初始化!这样才正确!

[ C ]. 展示名字:manager start failed :

在“info.plist”中必须添加“Bundle display name

在使用百度地图开发平台时,需要直接用“source code”方式,打开“info.plist”并添加:

  <key>CFBundleDisplayName</key>
       <string>BaiduDemo</string>

便可以了 !!!
(当然DisplayName(展示名字)是 可变的 )

[ D ]. 权限描述

iOS10点击有关权限访问,直接Crash。并在控制台输出了如下一些信息:

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

意思:你需要在“info.plist”文件中,添加一个“NSContactsUsageDescription”的Key,并为其Value添加一个描述

步骤:

1,在项目中找到“info.plist”文件,右击 “Open As”,以“Source Code” 的形式打开; 2,分别复制以下ValueKey,Key是一定不能错,Value可以随便填

   // 相机权限描述:

    NSCameraUsageDescription        cameraDesciption     // 通信录:        NSContactsUsageDescription        contactsDesciption     // 麦克风:     NSMicrophoneUsageDescription        microphoneDesciption     // 相机:     NSPhotoLibraryUsageDescription        photoLibraryDesciption

3,在“info.plist”文件里复制上,然后保存。并且Clean工程就好了。

[ E ]. PNG图片格式错误

打包的时候,出现这个警告! 意思是:png图片文件 失效 (png file invalid;)

重新导入一下png图片就ok了。但是 要知道“到底是哪张图片”出问题了。

[ F ]. 程序结束:Message from debugger: Terminated due to signal 9

原因:在调试的时候主动的结束了程度。 如:上滑、点击按钮等结束了程序。

[ G ]. AFNetworking请求、接收的格式问题

返回数据json”标准格式,会报如下错误:

Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object 
and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not 
start with array or object and option to allow fragments not set.}

原因:在默认情况下,AFNetworking的网络请求都是以json数据格式返回数据。因此,在客户端也会以json为默认格式

解决:需在发送请求前,加入下面代码:manager.responseSerializer = [AFHTTPResponseSerializer serializer]

[ H ]. 类型冲突:[__NSCFNumber length]: unrecognized selector sent to instance 0x8b3c310’

原因:NSNumber类型与NSString类型有冲突。 解决:将所需要相应属性的NSString类型 改为NSNumber类型(将属性类型设置为NSNumber), 而在调用时在将NSNumber类型 转成 NSString类型即可。

[ I ]. 两个.m文件:linker command failed with exit code 1 (use -vto see invocation)

原因:导入了“.m”的头文件,导致同时有两个一样的“.m文件 在编译。

[ J ]. Xcode真机测试报错:Could not launch...
  •  解决方案一:     1.删除“/Users/(用户名)/Library/Developer/Xcode/DerivedData/(对应APP程序)文件夹”里的内容;     2.拔掉手机,删除对应的APP应用,完全退出 Xcode工具;     3.重新连接手机进行真机测试

  • 解决方案二:     进行过真机抓包测试,关闭 HTTP代理

  • 解决方案三:     1.选择手机中“设置” → “通用” → “设备管理” → 选择自己对应的开发商应用 → “删除应用”;     2.重新运行Xcode中的程序,这个时候应该还会报错;     3.再次进入自己对应的开发商应用 → “验证应用”;     4.再次运行Xcode中的程序就OK了。     参:《个人账号 真机测试

[ K ]. 数据修改:Warning! ivar size mismatch in StepUICollectionView_ of 80 bytes - can't change the superclass.

解决: 1.搜索“StepUICollectionView”,找到“.m”文件; 2.搜索“char filler”,在“[ ]”中,将数据改为警告提示的数据。

[ L ]. Xib连线问题

原因:Xib中连线出问题

[ M ]. 没实现某方法

原因:某个对象没有实现某个方法

[ N ]. 网络代理:nw_proxy_resolver_create_parsed_array
2017-03-15 09:03:51.941774 cuteKids[1155:34545] PAC Fetch failed with error [NSURLErrorDomain:-1004]
2017-03-15 09:03:51.942688 cuteKids[1155:34545] [] nw_proxy_resolver_create_parsed_array PAC evaluation error: NSURLErrorDomain: -1004

原因:mac系统 网络代理问题。 解决:系统偏好设置网络高级代理,然后关闭自动代理”就好了。

警告
[ A ]. 字符串格式:Data argument not used by format string

原因:“[ stringWithFormat: ]”里面没有idx对应的格式引起的。 解决:修改里面为 相对应的格式

[ B ]. SB的属性未删除

Failed to set () user defined inspected property on (UILabel): [<UILabel 0x7febfcf4e7b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key .

原因:在增加了一些属性之后,却在代码中删除掉了,但是还是在UIStoryboard中保留

解决:所以需改掉(删除)相应的属性。

[ C ].键盘遮盖住了textview

报错:

2017-08-11 16:33:33.293831 cuteKids[10465:317797] 0x60800014d7e0 Copy matching assets reply: XPC_TYPE_DICTIONARY  <dictionary: 0x60800014d7e0> { count = 1, transaction: 0, voucher = 0x0, contents =
	"Result" => <int64: 0x60800003e260>: 29
}
 2017-08-11 16:33:33.294494 cuteKids[10465:317797] 0x60800014c8c0 Daemon configuration query reply: XPC_TYPE_DICTIONARY  <dictionary: 0x60800014c8c0> { count = 2, transaction: 0, voucher = 0x0, contents =
	"Dictionary" => <dictionary: 0x60800014c130> { count = 1, transaction: 0, voucher = 0x0, contents =
		"ServerURL" => <dictionary: 0x60800014daa0> { count = 3, transaction: 0, voucher = 0x0, contents =
			"com.apple.CFURL.magic" => <uuid: 0x608000249f30> C3853DCC-9776-4114-B6C1-FD9F51944A6D
	    	"com.apple.CFURL.string" => <string: 0x60800024bee0> { length = 30, contents = "https://mesu.apple.com/assets/" }
    		"com.apple.CFURL.base" => <null: 0x10ac19f20>: null-object
    	}
	}
	"Result" => <int64: 0x608000037fe0>: 0
}
 2017-08-11 16:33:33.294780 cuteKids[10465:317797] [MobileAssetError:29] Unable to copy asset information from https://mesu.apple.com/assets/ for asset type com.apple.MobileAsset.TextInput.SpellChecker

原因:由于键盘会遮盖住textview,所以需要实现键盘弹出修改scrollview的位置。

解决:

_mytextView.autocorrectionType = UITextAutocorrectionTypeNo; //⭐️必须添加⭐️
_mytextView.spellCheckingType = UITextSpellCheckingTypeNo;

[ D ].未添加协议:UITextFieldDelegate

警告:Assigning to 'id<UITextFieldDelegate> _Nullable' from incompatible type '某个ViewController *const __strong'

原因:提示分配给"UITextFieldDelegate"是类型有误的!

解决:添加**<UITextFieldDelegate>**协议

[ E ].CFNetwork internal error

警告:(控制台警告信息) 440: CFNetwork internal error (0xc01a:/BuildRoot/Library/Caches/com.apple.xbs/Sources/CFNetwork/CFNetwork-758.4.3/Loading/URLConnectionLoader.cpp:289)

解决:修改“info.plist”文件的“NSExceptionDomains”项!

NSExceptionAllowInsecureHTTPLoads : YES

NSExceptionRequiresForwardSecrecy : NO NSIncludesSubdomains : YES

Source Code”格式:

<key>NSAppTransportSecurity</key>
<dict>
	<key>NSAllowsArbitraryLoads</key>
	<true/>
	<key>NSExceptionAllowInsecureHTTPLoads</key>
	<true/>
	<key>NSExceptionDomains</key>
	<dict>
		<key>192.168.3.106</key>     <!-- 域地址 -->
		<dict>
			<key>NSExceptionRequiresForwardSecrecy</key>
			<false/>
			<key>NSIncludesSubdomains</key>
			<true/>
		</dict>
	</dict>
</dict>



更多文章 (参考\总结)

iOS警告收录及科学快速的消除方法

iOS工程的警告修复




2016.12.10

goyohol's essay